[llvm-commits] [llvm] r164912 - in /llvm/trunk: lib/Analysis/Lint.cpp test/Other/lint.ll

Duncan Sands baldrick at free.fr
Sun Sep 30 00:30:10 PDT 2012


Author: baldrick
Date: Sun Sep 30 02:30:10 2012
New Revision: 164912

URL: http://llvm.org/viewvc/llvm-project?rev=164912&view=rev
Log:
Ignore apparent buffer overruns on external or weak globals.  This is a major
source of false positives due to globals being declared in a header with some
kind of incomplete (small) type, but the actual definition being bigger.

Modified:
    llvm/trunk/lib/Analysis/Lint.cpp
    llvm/trunk/test/Other/lint.ll

Modified: llvm/trunk/lib/Analysis/Lint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Lint.cpp?rev=164912&r1=164911&r2=164912&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Lint.cpp (original)
+++ llvm/trunk/lib/Analysis/Lint.cpp Sun Sep 30 02:30:10 2012
@@ -430,13 +430,17 @@
         BaseAlign = AI->getAlignment();
         if (BaseAlign == 0 && ATy->isSized())
           BaseAlign = TD->getABITypeAlignment(ATy);
-      } else if (GlobalValue *GV = dyn_cast<GlobalVariable>(Base)) {
-        Type *GTy = GV->getType()->getElementType();
-        if (GTy->isSized())
-          BaseSize = TD->getTypeAllocSize(GTy);
-        BaseAlign = GV->getAlignment();
-        if (BaseAlign == 0 && GTy->isSized())
-          BaseAlign = TD->getABITypeAlignment(GTy);
+      } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
+        // If the global may be defined differently in another compilation unit
+        // then don't warn about funky memory accesses.
+        if (GV->hasDefinitiveInitializer()) {
+          Type *GTy = GV->getType()->getElementType();
+          if (GTy->isSized())
+            BaseSize = TD->getTypeAllocSize(GTy);
+          BaseAlign = GV->getAlignment();
+          if (BaseAlign == 0 && GTy->isSized())
+            BaseAlign = TD->getABITypeAlignment(GTy);
+        }
       }
 
       // Accesses from before the start or after the end of the object are not

Modified: llvm/trunk/test/Other/lint.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/lint.ll?rev=164912&r1=164911&r2=164912&view=diff
==============================================================================
--- llvm/trunk/test/Other/lint.ll (original)
+++ llvm/trunk/test/Other/lint.ll Sun Sep 30 02:30:10 2012
@@ -9,6 +9,7 @@
 declare void @one_arg(i32)
 
 @CG = constant i32 7
+ at E = external global i8
 
 define i32 @foo() noreturn {
   %buf = alloca i8
@@ -100,6 +101,10 @@
   ret i32 0
 
 foo:
+; CHECK-NOT: Undefined behavior: Buffer overflow
+; CHECK-NOT: Memory reference address is misaligned
+  %e = bitcast i8* @E to i64*
+  store i64 0, i64* %e
   %z = add i32 0, 0
 ; CHECK: unreachable immediately preceded by instruction without side effects
   unreachable





More information about the llvm-commits mailing list