diff options
author | Duncan Sands <baldrick@free.fr> | 2012-09-30 07:30:10 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2012-09-30 07:30:10 +0000 |
commit | b620469223d3135361978668c1f5b0739e5cbaa1 (patch) | |
tree | 148088e6c1f60e03eb56818ec01b1407dcfc1327 /lib/Analysis/Lint.cpp | |
parent | 73fab91f2cd5fa3dbe4593506ac4a31aa3faf897 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164912 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/Lint.cpp')
-rw-r--r-- | lib/Analysis/Lint.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/Analysis/Lint.cpp b/lib/Analysis/Lint.cpp index 9258aeee55..7bd945733b 100644 --- a/lib/Analysis/Lint.cpp +++ b/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 |