aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/ScanfFormatString.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2016-08-20 16:51:33 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2016-08-20 16:51:33 +0000
commitf3b323debc949cf67cb395337fc0d5d5b26c21b9 (patch)
treed53992293b16f139b66f2effb259cbf0a057f031 /clang/lib/Analysis/ScanfFormatString.cpp
parentf9fd63ad39936968e5b81a5ad5d269ffa761604c (diff)
downloadllvm-f3b323debc949cf67cb395337fc0d5d5b26c21b9.zip
llvm-f3b323debc949cf67cb395337fc0d5d5b26c21b9.tar.gz
llvm-f3b323debc949cf67cb395337fc0d5d5b26c21b9.tar.bz2
[Sema] Don't crash on scanf on forward-declared enums.
This is valid in GNU C, which allows pointers to incomplete enums. GCC just pretends that the underlying type is 'int' in those cases, follow that behavior. llvm-svn: 279374
Diffstat (limited to 'clang/lib/Analysis/ScanfFormatString.cpp')
-rw-r--r--clang/lib/Analysis/ScanfFormatString.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Analysis/ScanfFormatString.cpp b/clang/lib/Analysis/ScanfFormatString.cpp
index 82b0388..3b93f1a 100644
--- a/clang/lib/Analysis/ScanfFormatString.cpp
+++ b/clang/lib/Analysis/ScanfFormatString.cpp
@@ -418,8 +418,12 @@ bool ScanfSpecifier::fixType(QualType QT, QualType RawQT,
QualType PT = QT->getPointeeType();
// If it's an enum, get its underlying type.
- if (const EnumType *ETy = PT->getAs<EnumType>())
+ if (const EnumType *ETy = PT->getAs<EnumType>()) {
+ // Don't try to fix incomplete enums.
+ if (!ETy->getDecl()->isComplete())
+ return false;
PT = ETy->getDecl()->getIntegerType();
+ }
const BuiltinType *BT = PT->getAs<BuiltinType>();
if (!BT)