-Cllvm-args=-fanalyzer reports uses of uninitialized values
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
使用所示的 Box::new(42) 程序和 -Cllvm-args=-fanalyzer 重现该警告,然后通过 rustc_codegen_gcc 构建的 sysroot 文件跟踪报告的路径,包括 core/src/alloc/layout.rs、core/src/ub_checks.rs、alloc/src/alloc.rs 和 alloc/src/boxed.rs。当重现过程不再报告这些未初始化值警告,并且受影响的分配和布局路径具有适当的覆盖率时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
#[unsafe(no_mangle)]
fn main() {
let _ = Box::new(42);
}
and then compile with -Cllvm-args=-fanalyzer results in
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 1
│
│ (1): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 2
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:78:17:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 3
│
│libgccjit.so:
│ (3): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 4
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:138:18:
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 5
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:75:14:
│
<──────┘
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 6
│
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 7
│
│libgccjit.so:
│ (7): use of uninitialized value 'undefined' here
│
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'_ZN5alloc5alloc15exchange_malloc17h3ccaf01f6c22a3acE': event 1
│
│libgccjit.so:
│ (1): entry to '_ZN5alloc5alloc15exchange_malloc17h3ccaf01f6c22a3acE'
│
'_ZN5alloc5alloc15exchange_malloc17h3ccaf01f6c22a3acE': event 2
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/alloc/src/alloc.rs:351:27:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 3
│
│libgccjit.so:
│ (3): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 4
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:78:17:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 5
│
│libgccjit.so:
│ (5): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 6
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:138:18:
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 7
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:75:14:
│
<──────┘
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 8
│
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 9
│
│libgccjit.so:
│ (9): use of uninitialized value 'undefined' here
│
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'main': event 1
│
│libgccjit.so:
│ (1): entry to 'main'
│
'main': event 2
│
│<source>:3:13:
│ 3 | let _ = Box::new(42);
│ | ^
│ | |
│ | (2) inlined call to '_ZN5alloc5boxed12Box$LT$T$GT$3new17h4d326128f3fc6045E' from 'main'
│
└──> '_ZN5alloc5boxed12Box$LT$T$GT$3new17h4d326128f3fc6045E': event 3
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/alloc/src/boxed.rs:261:16:
│
'_ZN5alloc5alloc15exchange_malloc17h3ccaf01f6c22a3acE': event 4
│
│libgccjit.so:
│ (4): entry to '_ZN5alloc5alloc15exchange_malloc17h3ccaf01f6c22a3acE'
│
'_ZN5alloc5alloc15exchange_malloc17h3ccaf01f6c22a3acE': event 5
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/alloc/src/alloc.rs:351:27:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 6
│
│libgccjit.so:
│ (6): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 7
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:78:17:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 8
│
│libgccjit.so:
│ (8): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 9
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:138:18:
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 10
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:75:14:
│
<──────┘
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 11
│
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 12
│
│libgccjit.so:
│ (12): use of uninitialized value 'undefined' here
│
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'_ZN5alloc5alloc6Global10alloc_impl17h0be00c1c456dfa5cE': events 1-2
/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/alloc/src/alloc.rs:186:9:
'_ZN5alloc5alloc6Global10alloc_impl17h0be00c1c456dfa5cE': event 3
libgccjit.so:
(3): use of uninitialized value 'undefined' here
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'_ZN63_$LT$alloc..alloc..Global$u20$as$u20$core..alloc..Allocator$GT$8allocate17h69f42b4c603da6acE': event 1
│
│libgccjit.so:
│ (1): entry to '_ZN63_$LT$alloc..alloc..Global$u20$as$u20$core..alloc..Allocator$GT$8allocate17h69f42b4c603da6acE'
│
'_ZN63_$LT$alloc..alloc..Global$u20$as$u20$core..alloc..Allocator$GT$8allocate17h69f42b4c603da6acE': event 2
│
│
└──> '_ZN5alloc5alloc6Global10alloc_impl17h0be00c1c456dfa5cE': event 3
│
│libgccjit.so:
│ (3): entry to '_ZN5alloc5alloc6Global10alloc_impl17h0be00c1c456dfa5cE'
│
'_ZN5alloc5alloc6Global10alloc_impl17h0be00c1c456dfa5cE': events 4-5
│
│
'_ZN5alloc5alloc6Global10alloc_impl17h0be00c1c456dfa5cE': event 6
│
│libgccjit.so:
│ (6): use of uninitialized value 'undefined' here
│
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E': event 1
│
│libgccjit.so:
│ (1): entry to '_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E'
│
'_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E': event 2
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:224:18:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 3
│
│libgccjit.so:
│ (3): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 4
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:78:17:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 5
│
│libgccjit.so:
│ (5): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 6
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:138:18:
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 7
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:75:14:
│
<──────┘
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 8
│
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 9
│
│libgccjit.so:
│ (9): use of uninitialized value 'undefined' here
│
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'_ZN72_$LT$alloc..boxed..Box$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h7863c2941af28a7cE': event 1
│
│libgccjit.so:
│ (1): entry to '_ZN72_$LT$alloc..boxed..Box$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h7863c2941af28a7cE'
│
'_ZN72_$LT$alloc..boxed..Box$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h7863c2941af28a7cE': event 2
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/alloc/src/boxed.rs:1652:26:
│
└──> '_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E': event 3
│
│libgccjit.so:
│ (3): entry to '_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E'
│
'_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E': event 4
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:224:18:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 5
│
│libgccjit.so:
│ (5): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 6
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:78:17:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 7
│
│libgccjit.so:
│ (7): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 8
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:138:18:
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 9
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:75:14:
│
<──────┘
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 10
│
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 11
│
│libgccjit.so:
│ (11): use of uninitialized value 'undefined' here
│
libgccjit.so: warning: : use of uninitialized value 'undefined' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
'_ZN4core3ptr49drop_in_place$LT$alloc..boxed..Box$LT$i32$GT$$GT$17h2d9920e239d4edd1E': event 1
│
│libgccjit.so:
│ (1): entry to '_ZN4core3ptr49drop_in_place$LT$alloc..boxed..Box$LT$i32$GT$$GT$17h2d9920e239d4edd1E'
│
'_ZN4core3ptr49drop_in_place$LT$alloc..boxed..Box$LT$i32$GT$$GT$17h2d9920e239d4edd1E': event 2
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ptr/mod.rs:804:1:
│
└──> '_ZN72_$LT$alloc..boxed..Box$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h7863c2941af28a7cE': event 3
│
│libgccjit.so:
│ (3): entry to '_ZN72_$LT$alloc..boxed..Box$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h7863c2941af28a7cE'
│
'_ZN72_$LT$alloc..boxed..Box$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h7863c2941af28a7cE': event 4
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/alloc/src/boxed.rs:1652:26:
│
└──> '_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E': event 5
│
│libgccjit.so:
│ (5): entry to '_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E'
│
'_ZN4core5alloc6layout6Layout13for_value_raw17hfb84ae9010274903E': event 6
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:224:18:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 7
│
│libgccjit.so:
│ (7): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 8
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:78:17:
│
└──> '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 9
│
│libgccjit.so:
│ (9): entry to '_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E'
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 10
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/alloc/layout.rs:138:18:
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked18precondition_check17h7567f7e907a542e2E': event 11
│
│/root/build-rustc-cg-gcc/rustc_codegen_gcc/build/build_sysroot/sysroot_src/library/core/src/ub_checks.rs:75:14:
│
<──────┘
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 12
│
│
'_ZN4core5alloc6layout6Layout25from_size_align_unchecked17h70ce6625d1a2bfa4E': event 13
│
│libgccjit.so:
│ (13): use of uninitialized value 'undefined' here
│
simple true UB things like
#[unsafe(no_mangle)]
fn main() {
unsafe { *core::ptr::null_mut() = 42; }
}
are correctly reported with -Cllvm-args=-fanalyzer -O though, so -fanalyzer is not completely broken:
libgccjit.so: <source>:3:14: warning: : dereference of NULL '0B' [CWE-476] [-Wanalyzer-null-dereference]
'main': event 1
<source>:3:14:
3 | unsafe { *core::ptr::null_mut() = 42; }
| ^
| |
| (1) ⚠️ dereference of NULL '0B'
but something like
#[unsafe(no_mangle)]
fn main() {
let x = 42;
let bad_box = unsafe { std::mem::transmute::<&i32, Box<i32>>(&x) };
drop(bad_box);
}
doesn't get any errors with -Cllvm-args=-fanalyzer -O (likely because __rust_dealloc is not recognized as free function by GCC, while without -O it produces the same warnings about uninitialized values.
- 主要语言
- Rust
- 星标
- 1.2k
- 派生
- 105
- 平均合并
- 10 小时 31 分钟
- 30 天内合并 PR
- 27
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/rustc_codegen_gcc 的其他 Issue
-
tests
难度 2/5 1-3 小时 新手友好度 62/100
rust-lang/rustc_codegen_gcc#993 ·
维护者通常 1 天内回复
-
Cannot compile sysroot if having a build.build-dir cargo config可能已有人在做 @GuillaumeGomez 于 8 天前认领。 未关闭
rust-lang/rustc_codegen_gcc#1011 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
tests
难度 4/5 3-5 天 新手友好度 30/100
rust-lang/rustc_codegen_gcc#992 ·
维护者通常 1 天内回复
-
bug
难度 5/5 一周以上 新手友好度 35/100
rust-lang/rustc_codegen_gcc#970 · 5 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
rust-lang/rustc_codegen_gcc#943 ·
维护者通常 1 天内回复
查看 rust-lang/rustc_codegen_gcc 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
haowjy/mars-agents#295 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 85/100
-
难度 2/5 1-3 小时 新手友好度 78/100
rivet-dev/rivet#5933 · 1 条评论 ·
维护者通常 1 天内回复
-
needs-verification
难度 2/5 1-3 小时 新手友好度 72/100
EchoTools/nevr-runtime#1272 ·
维护者通常 1 天内回复
-
Add a `--skip-readme` option to `gleam new`可能已有人在做 @mine-tech-oficial 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
gleam-lang/gleam#6458 · 1 个 reaction ·
维护者通常 1 天内回复