[llvm-bugs] [Bug 28249] New: Missing warning about uninitialized var when going through a pointer
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jun 21 14:34:53 PDT 2016
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: unassignedclangbugs at nondot.org
Reporter: ch3root at openwall.com
CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160621/3a91851c/attachment.html>
More information about the llvm-bugs
mailing list