Skip to content

Commit 7cff2e7

Browse files
committed
扩展C11原生与WASM差分语料并绑定逐例证据
1 parent ed490db commit 7cff2e7

5 files changed

Lines changed: 193 additions & 5 deletions

File tree

‎crates/codeguard-cli/tests/c_native_differential.rs‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#![cfg(all(feature = "wasm-precheck", unix))]
22

33
use std::fs;
4+
use sha2::{Digest, Sha256};
45
use std::path::Path;
56
use std::process::Command;
67

7-
fn corpus() -> [(&'static str, &'static str, bool); 13] {
8+
fn corpus() -> [(&'static str, &'static str, bool); 19] {
89
[
910
("function", "int main(void) { return 0; }\n", true),
1011
("pointer", "int f(const int *x) { return *x; }\n", true),
@@ -30,6 +31,12 @@ fn corpus() -> [(&'static str, &'static str, bool); 13] {
3031
"#define VALUE 1\nint f(void) { return VALUE; }\n",
3132
true,
3233
),
34+
("static_assert", "_Static_assert(sizeof(int) > 0, \"int size\");\n" , true),
35+
("generic_selection", "int f(void) { return _Generic(1, int: 2, default: 0); }\n", true),
36+
("variable_length_array", "int f(int n) { int values[n]; return sizeof(values) > 0; }\n", true),
37+
("function_pointer", "int (*handler)(int);\n", true),
38+
("broken_static_assert", "_Static_assert(, \"broken\");\n", false),
39+
("broken_generic", "int f(void) { return _Generic(1, int: ); }\n", false),
3340
("missing_brace", "int main(void) { return 0;\n", false),
3441
("missing_semicolon", "int x = 1\n", false),
3542
(
@@ -97,6 +104,7 @@ fn pinned_c_worker_matches_native_clang_on_syntax_corpus() {
97104
.unwrap()
98105
.join(format!("codeguard-c-differential-{}", std::process::id()));
99106
fs::create_dir_all(&root).unwrap();
107+
let mut cases = Vec::new();
100108
for (name, source, expected_valid) in corpus() {
101109
let file = root.join(format!("{name}.c"));
102110
fs::write(&file, source).unwrap();
@@ -126,12 +134,32 @@ fn pinned_c_worker_matches_native_clang_on_syntax_corpus() {
126134
source,
127135
"{name}: native mutated source"
128136
);
137+
let candidate_valid = candidate_is_valid(&root, name, source);
129138
assert_eq!(
130-
candidate_is_valid(&root, name, source),
139+
candidate_valid,
131140
native.status.success(),
132141
"{name}: clang={} worker classification differs",
133142
String::from_utf8_lossy(&native.stderr)
134143
);
144+
cases.push(serde_json::json!({"case":name,"source_sha256":format!("{:x}",Sha256::digest(source.as_bytes())),"expected_valid":expected_valid,"native_exit":native.status.code(),"candidate_valid":candidate_valid}));
145+
}
146+
if let Ok(output) = std::env::var("CODEGUARD_C_DIFFERENTIAL_EVIDENCE") {
147+
let output = Path::new(&output);
148+
assert!(output.is_absolute(), "evidence path must be absolute");
149+
let evidence = serde_json::json!({
150+
"evidence_kind":"development_c11_native_wasm_differential",
151+
"qualification":"not_granted",
152+
"independent_holdout":false,
153+
"standard":"c11",
154+
"compiler_version":String::from_utf8_lossy(&version.stdout),
155+
"compiler_sha256":format!("{:x}",Sha256::digest(fs::read(&clang).unwrap())),
156+
"cli_sha256":format!("{:x}",Sha256::digest(fs::read(env!("CARGO_BIN_EXE_codeguard")).unwrap())),
157+
"test_source_sha256":format!("{:x}",Sha256::digest(include_bytes!("c_native_differential.rs"))),
158+
"grammar_manifest_sha256":format!("{:x}",Sha256::digest(fs::read(Path::new(env!("CARGO_MANIFEST_DIR")).join("../../grammars/manifest.json")).unwrap())),
159+
"case_count":cases.len(),"cases":cases,
160+
"delivery_decision":"not_evaluated"
161+
});
162+
fs::write(output, serde_json::to_vec_pretty(&evidence).unwrap()).unwrap();
135163
}
136164
fs::remove_dir_all(root).unwrap();
137165
}

‎rulepacks/production_acceptance_plan_v1.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@
269269
"tests/acceptance/c-family-documentation-hook.md": "b485ed377737804c72222ee93daf5aade73c6ec46987ef2e7bc73ac2aa32eb50",
270270
"tests/acceptance/evidence/c-family-documentation-hook-default.json": "418e39790d61b891cca7885c66c9e311ab33dbbdd836bc3241cae0c11b0b9244",
271271
"tests/acceptance/evidence/c-family-documentation-hook-wasm.json": "d4b7b4806d9786280f7d4f3f60f47cd9e7e2882d839e43b7044d96fcef454698",
272-
"tests/acceptance/evidence/c-family-documentation-hook-schema.json": "a7e733a30ea12e3aa1fac96e634c94b049ca313b93a4282e6d3971c046656218"
272+
"tests/acceptance/evidence/c-family-documentation-hook-schema.json": "a7e733a30ea12e3aa1fac96e634c94b049ca313b93a4282e6d3971c046656218",
273+
"crates/codeguard-cli/tests/c_native_differential.rs": "64ca1db5036fc0b212ce6a1aa68a8411de168326e41e1fdc7b5249def65db1c8",
274+
"tests/acceptance/c-native-differential.md": "db025338f59a880275b697d4dd8e3c47ec5e2f888cb456e4781ff4f956de1247",
275+
"tests/acceptance/evidence/c11-native-wasm-differential.json": "7a2dccf79dc752f8675c4caa3ce80db60361eb46dd10038878c8e1c89c32f531"
273276
},
274277
"languages": [
275278
{
@@ -2992,7 +2995,10 @@
29922995
"tests/acceptance/clang-standalone-native.md",
29932996
"tests/acceptance/clang-preprocessor-context.md",
29942997
"tests/acceptance/c-family-native-replay.md",
2995-
"tests/acceptance/c-family-native-punctuation.md"
2998+
"tests/acceptance/c-family-native-punctuation.md",
2999+
"crates/codeguard-cli/tests/c_native_differential.rs",
3000+
"tests/acceptance/c-native-differential.md",
3001+
"tests/acceptance/evidence/c11-native-wasm-differential.json"
29963002
],
29973003
"blockers": [
29983004
"c/standalone:完整原生语法版本/方言、源集、WASM联合路径及独立精度未验收",

‎tests/acceptance/c-native-differential.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
首次语料把 `int f(void) { return ; + 1; }` 误标为语法错误:Clang 因返回类型拒绝,但 Tree-sitter 对该语法不产生恢复节点。这是语义差异,不作为 grammar 漏检。改成 `int x = ;` 后两者同为语法拒绝。测试避免把编译器的类型/语义检查与语法恢复等同。
1010

1111
此对照只覆盖本机 Clang 版本及 C11 的 13 份小样例。`-fsyntax-only` 还会执行语义检查;语料标签已经人工核对为语法范围,但不代表 Clang 诊断均是 grammar 可检的内容。当前 grammar 仍 `grammar_qualified=false`,零恢复节点不表示原生 lint 或交付通过。尚无独立 holdout、系统误报/漏报率、跨平台版本、完整原生优先路由和宿主反馈,父任务不勾选。
12+
13+
## C11边界语料补充
14+
15+
当前语料扩展为19例,新增静态断言、泛型选择、变长数组、函数指针,以及破损静态断言/泛型选择。显式CODEGUARD_CLANG_BIN=/usr/bin/clang,offline/locked启用wasm-precheck并执行include-ignored:固定语料与实际原生差分2/2通过、无忽略;19例分类一致。此前13例为历史检查点。新增样例仍来自同一开发语料,不能替代独立holdout、误报率或全平台资格。编辑快检目前缺Clang标准上下文接线,此结果不证明自动调度完成。
16+
17+
逐例证据:evidence/c11-native-wasm-differential.json,由真实差分测试通过后写入;绑定测试源码、Clang二进制、Codeguard二进制和grammar清单SHA256,并保存19例输入摘要、原生退出码及WASM分类。标记independent_holdout=false与qualification=not_granted。可通过绝对CODEGUARD_C_DIFFERENTIAL_EVIDENCE路径重新采集。
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"case_count": 19,
3+
"cases": [
4+
{
5+
"candidate_valid": true,
6+
"case": "function",
7+
"expected_valid": true,
8+
"native_exit": 0,
9+
"source_sha256": "2ad75d95660563887d8d3f1d0ae1dcf18c2379cbd83a5c72f5ab276351ee6949"
10+
},
11+
{
12+
"candidate_valid": true,
13+
"case": "pointer",
14+
"expected_valid": true,
15+
"native_exit": 0,
16+
"source_sha256": "cf6844dae4e58b7b5086281300686d9956587fd656cfc903b6ca4205ab8b05cf"
17+
},
18+
{
19+
"candidate_valid": true,
20+
"case": "structure",
21+
"expected_valid": true,
22+
"native_exit": 0,
23+
"source_sha256": "ae291bd67be51e38548f08b410a8e7a2f5390fdf56b8fde16b439dcb0ddae9c6"
24+
},
25+
{
26+
"candidate_valid": true,
27+
"case": "typedef",
28+
"expected_valid": true,
29+
"native_exit": 0,
30+
"source_sha256": "71a8c9fe077a5757900051c50d3d1584eec77fa9f1b40ec9a958ff90768f687c"
31+
},
32+
{
33+
"candidate_valid": true,
34+
"case": "enumeration",
35+
"expected_valid": true,
36+
"native_exit": 0,
37+
"source_sha256": "dae545f9c672322cc57cab11dee9937773259c19b57296da966f92af81414422"
38+
},
39+
{
40+
"candidate_valid": true,
41+
"case": "compound_literal",
42+
"expected_valid": true,
43+
"native_exit": 0,
44+
"source_sha256": "0262f0063ca13190d16558e60e8589a408abc64c2626d11f5f30bfc79bc09b30"
45+
},
46+
{
47+
"candidate_valid": true,
48+
"case": "designated",
49+
"expected_valid": true,
50+
"native_exit": 0,
51+
"source_sha256": "952e976574117940e84983d6c6f80d4f9ccca2f96171b696ddc578c700fcd39a"
52+
},
53+
{
54+
"candidate_valid": true,
55+
"case": "preprocessor",
56+
"expected_valid": true,
57+
"native_exit": 0,
58+
"source_sha256": "26a62ddd5446e54b587276346a4ea2815d50ae217985691507b50889b06cf423"
59+
},
60+
{
61+
"candidate_valid": true,
62+
"case": "static_assert",
63+
"expected_valid": true,
64+
"native_exit": 0,
65+
"source_sha256": "fd57efb0face93373fd077f54a09e989f5b1db7c937e2f67ce69b28ac6a2794f"
66+
},
67+
{
68+
"candidate_valid": true,
69+
"case": "generic_selection",
70+
"expected_valid": true,
71+
"native_exit": 0,
72+
"source_sha256": "7616705e6ccf55899656233238014467f55b02b1ec90ab4a9a3e9df189ad46f3"
73+
},
74+
{
75+
"candidate_valid": true,
76+
"case": "variable_length_array",
77+
"expected_valid": true,
78+
"native_exit": 0,
79+
"source_sha256": "a47e13a2950f0953b23003fa27b2a485a406b64bec58a2a970b013f487d4b76f"
80+
},
81+
{
82+
"candidate_valid": true,
83+
"case": "function_pointer",
84+
"expected_valid": true,
85+
"native_exit": 0,
86+
"source_sha256": "d6f9e9ed000becea0545dbc8b4d09e5cd7dee181039ea0e9cc64823571858743"
87+
},
88+
{
89+
"candidate_valid": false,
90+
"case": "broken_static_assert",
91+
"expected_valid": false,
92+
"native_exit": 1,
93+
"source_sha256": "c74d6e9eaf83961df67c2ab8bf12d871776d78e3f047ec912fc735858945c725"
94+
},
95+
{
96+
"candidate_valid": false,
97+
"case": "broken_generic",
98+
"expected_valid": false,
99+
"native_exit": 1,
100+
"source_sha256": "f2c9bc0f10b535a9afed22dbd9148facbde9f3dabcc03b76f7d40d8d42f8692b"
101+
},
102+
{
103+
"candidate_valid": false,
104+
"case": "missing_brace",
105+
"expected_valid": false,
106+
"native_exit": 1,
107+
"source_sha256": "0bc3da61edcc941a330fc090fc3390a7ea28f7136fbc60e934fd2cc54c83f4a0"
108+
},
109+
{
110+
"candidate_valid": false,
111+
"case": "missing_semicolon",
112+
"expected_valid": false,
113+
"native_exit": 1,
114+
"source_sha256": "e7f9512d79642a7d530ad4765b233b53c5aec858ee408ad48fcadd7f639634f8"
115+
},
116+
{
117+
"candidate_valid": false,
118+
"case": "missing_expr",
119+
"expected_valid": false,
120+
"native_exit": 1,
121+
"source_sha256": "e1f3b4ab3ae6a0b2e7b60ba21a983545382a41487282a37c0eba1698250b5950"
122+
},
123+
{
124+
"candidate_valid": false,
125+
"case": "unclosed_string",
126+
"expected_valid": false,
127+
"native_exit": 1,
128+
"source_sha256": "74a2152326de9077ec6bfd8f276986cda9d4b718701c2bb64a4dfad1df694c5a"
129+
},
130+
{
131+
"candidate_valid": false,
132+
"case": "bad_declarator",
133+
"expected_valid": false,
134+
"native_exit": 1,
135+
"source_sha256": "f11f99927226d3ebc8b6c8c49ab1379403f9232234c3c9f4c911c9c29bde474f"
136+
}
137+
],
138+
"cli_sha256": "fc1afbd09cfa06138c2726aee904e5399e0216004571c69b8a0a14a2ee22f800",
139+
"compiler_sha256": "34129c71a01a74f7f3b2443521519b2e5447553fa187f5fcafaaf8c42cc192e2",
140+
"compiler_version": "Apple clang version 21.0.0 (clang-2100.3.34.2)\nTarget: arm64-apple-darwin27.0.0\nThread model: posix\nInstalledDir: /Library/Developer/CommandLineTools/usr/bin\n",
141+
"delivery_decision": "not_evaluated",
142+
"evidence_kind": "development_c11_native_wasm_differential",
143+
"grammar_manifest_sha256": "9fe2fa77181aedd74755a2ac5b8fe694b2d4f2d33f03518d814476a911b2a610",
144+
"independent_holdout": false,
145+
"qualification": "not_granted",
146+
"standard": "c11",
147+
"test_source_sha256": "64ca1db5036fc0b212ce6a1aa68a8411de168326e41e1fdc7b5249def65db1c8"
148+
}

‎tests/acceptance/evidence/production-acceptance-plan/all.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)