https://llvm.org/bugs/show_bug.cgi?id=28249
Bug ID: 28249 Summary: Missing warning about uninitialized var when going through a pointer Product: clang Version: trunk Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: -New Bugs Assignee: unassignedclangb...@nondot.org Reporter: ch3r...@openwall.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified Source code: ---------------------------------------------------------------------- #include <stdio.h> int main() { int i; printf("%d\n", *(int *)&i); } ---------------------------------------------------------------------- Results: ---------------------------------------------------------------------- $ clang -std=c11 -Weverything -O3 test.c && ./a.out -1069783944 ---------------------------------------------------------------------- clang version: clang version 3.9.0 (trunk 271312) For comparison: ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out test.c: In function ‘main’: test.c:6:3: warning: ‘i’ is used uninitialized in this function [-Wuninitialized] printf("%d\n", *(int *)&i); ^~~~~~~~~~~~~~~~~~~~~~~~~~ 0 ---------------------------------------------------------------------- gcc version: gcc (GCC) 7.0.0 20160616 (experimental) The optimizer sees that an undef value is used: ---------------------------------------------------------------------- *** IR Dump After SROA *** ; Function Attrs: nounwind uwtable define i32 @main() #0 { entry: %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 undef) ret i32 0 } ---------------------------------------------------------------------- but nevertheless a warning is not emitted. The code in the testcase is useless but the same happens when a representation of an uninitialized variable is accessed, i.e. there is no warning for `*(char *)&i`. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs