[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
This commit is contained in:
Benjamin Kramer
2016-08-20 16:51:33 +00:00
parent f9fd63ad39
commit f3b323debc
3 changed files with 35 additions and 4 deletions

View File

@@ -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)