]> granicus.if.org Git - clang/commitdiff
Fix uninitialized value in AttributedTypeLoc.
authorLogan Chien <tzuhsiang.chien@gmail.com>
Sun, 9 Mar 2014 16:21:03 +0000 (16:21 +0000)
committerLogan Chien <tzuhsiang.chien@gmail.com>
Sun, 9 Mar 2014 16:21:03 +0000 (16:21 +0000)
Clang might crash while reading the precompiled headers if
we don't initialize the AttrEnumOperandLoc properly.

This commit fixes the combination of string attribute
operand and enum operand.  Besides, this commit also adds
several assertions to avoid unexpected operand kind.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203416 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp

index 7ba824b909b4436e8e69fe414323665af3047454..1f6543875bbf1e0def55e14a10d8b7b28f4ae954 100644 (file)
@@ -3444,10 +3444,17 @@ static void fillAttributedTypeLoc(AttributedTypeLoc TL,
   }
 
   TL.setAttrNameLoc(attrs->getLoc());
-  if (TL.hasAttrExprOperand() && attrs->isArgExpr(0))
+  if (TL.hasAttrExprOperand()) {
+    assert(attrs->isArgExpr(0) && "mismatched attribute operand kind");
     TL.setAttrExprOperand(attrs->getArgAsExpr(0));
-  else if (TL.hasAttrEnumOperand() && attrs->isArgIdent(0))
-    TL.setAttrEnumOperandLoc(attrs->getArgAsIdent(0)->Loc);
+  } else if (TL.hasAttrEnumOperand()) {
+    assert((attrs->isArgIdent(0) || attrs->isArgExpr(0)) &&
+           "unexpected attribute operand kind");
+    if (attrs->isArgIdent(0))
+      TL.setAttrEnumOperandLoc(attrs->getArgAsIdent(0)->Loc);
+    else
+      TL.setAttrEnumOperandLoc(attrs->getArgAsExpr(0)->getExprLoc());
+  }
 
   // FIXME: preserve this information to here.
   if (TL.hasAttrOperand())