summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/Lint.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-09-30 07:30:10 +0000
committerDuncan Sands <baldrick@free.fr>2012-09-30 07:30:10 +0000
commit5e561bbd5dcedf5338e939ef8ead1eadd797240c (patch)
tree44e4923aa6a1230925d50baf15f5ebf9daf14e06 /llvm/lib/Analysis/Lint.cpp
parentabbe66515447824b427e7c340ef8253ecac4061c (diff)
downloadbcm5719-llvm-5e561bbd5dcedf5338e939ef8ead1eadd797240c.tar.gz
bcm5719-llvm-5e561bbd5dcedf5338e939ef8ead1eadd797240c.zip
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. llvm-svn: 164912
Diffstat (limited to 'llvm/lib/Analysis/Lint.cpp')
-rw-r--r--llvm/lib/Analysis/Lint.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index 9258aeee550..7bd945733b4 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -430,13 +430,17 @@ void Lint::visitMemoryReference(Instruction &I,
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
OpenPOWER on IntegriCloud