r203416 - Fix uninitialized value in AttributedTypeLoc.

Logan Chien tzuhsiang.chien at gmail.com
Sun Mar 9 09:21:04 PDT 2014


Author: logan
Date: Sun Mar  9 11:21:03 2014
New Revision: 203416

URL: http://llvm.org/viewvc/llvm-project?rev=203416&view=rev
Log:
Fix uninitialized value in AttributedTypeLoc.

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.


Modified:
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=203416&r1=203415&r2=203416&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sun Mar  9 11:21:03 2014
@@ -3444,10 +3444,17 @@ static void fillAttributedTypeLoc(Attrib
   }
 
   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())





More information about the cfe-commits mailing list