Hello.  I've attached a small patch that fixes the 15095 bug I filed a
couple of days ago, and makes sure that the CompoundLiteral and child
AST nodes created from a vector literal have correct source-location
information.  Does this make sense to the veteran Clang developers?

Thanks,
--John
Index: include/clang/Sema/Sema.h
===================================================================
--- include/clang/Sema/Sema.h	(revision 173717)
+++ include/clang/Sema/Sema.h	(working copy)
@@ -3178,8 +3178,10 @@
   CastKind PrepareScalarCast(ExprResult &src, QualType destType);
 
   /// \brief Build an altivec or OpenCL literal.
-  ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
-                                SourceLocation RParenLoc, Expr *E,
+  ExprResult BuildVectorLiteral(SourceLocation castLParenLoc,
+                                SourceLocation castRParenLoc, Expr *E,
+                                SourceLocation litLParenLoc,
+                                SourceLocation litRParenLoc,
                                 TypeSourceInfo *TInfo);
 
   ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp	(revision 173717)
+++ lib/Sema/SemaExpr.cpp	(working copy)
@@ -4584,8 +4584,12 @@
 
   // If this is a vector initializer, '(' type ')' '(' init, ..., init ')'
   // then handle it as such.
-  if (isVectorLiteral)
-    return BuildVectorLiteral(LParenLoc, RParenLoc, CastExpr, castTInfo);
+  if (isVectorLiteral) {
+    SourceLocation litLParenLoc = (PE ? PE->getLParen() : PLE->getLParenLoc());
+    SourceLocation litRParenLoc = (PE ? PE->getRParen() : PLE->getRParenLoc());
+    return BuildVectorLiteral(LParenLoc, RParenLoc, CastExpr, litLParenLoc, 
+                              litRParenLoc, castTInfo);
+  }
 
   // If the Expr being casted is a ParenListExpr, handle it specially.
   // This is not an AltiVec-style cast, so turn the ParenListExpr into a
@@ -4599,8 +4603,10 @@
   return BuildCStyleCastExpr(LParenLoc, castTInfo, RParenLoc, CastExpr);
 }
 
-ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc,
-                                    SourceLocation RParenLoc, Expr *E,
+ExprResult Sema::BuildVectorLiteral(SourceLocation castLParenLoc,
+                                    SourceLocation castRParenLoc, Expr *E,
+                                    SourceLocation litLParenLoc,
+                                    SourceLocation litRParenLoc,
                                     TypeSourceInfo *TInfo) {
   assert((isa<ParenListExpr>(E) || isa<ParenExpr>(E)) &&
          "Expected paren or paren list expression");
@@ -4639,7 +4645,8 @@
         return ExprError();
       Literal = ImpCastExprToType(Literal.take(), ElemTy,
                                   PrepareScalarCast(Literal, ElemTy));
-      return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.take());
+      return BuildCStyleCastExpr(castLParenLoc, TInfo, castRParenLoc, 
+                                 Literal.take());
     }
     else if (numExprs < numElems) {
       Diag(E->getExprLoc(),
@@ -4661,17 +4668,18 @@
           return ExprError();
         Literal = ImpCastExprToType(Literal.take(), ElemTy,
                                     PrepareScalarCast(Literal, ElemTy));
-        return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.take());
+        return BuildCStyleCastExpr(castLParenLoc, TInfo, castRParenLoc, 
+                                   Literal.take());
     }
     
     initExprs.append(exprs, exprs + numExprs);
   }
   // FIXME: This means that pretty-printing the final AST will produce curly
   // braces instead of the original commas.
-  InitListExpr *initE = new (Context) InitListExpr(Context, LParenLoc,
-                                                   initExprs, RParenLoc);
+  InitListExpr *initE = new (Context) InitListExpr(Context, litLParenLoc,
+                                                   initExprs, litRParenLoc);
   initE->setType(Ty);
-  return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, initE);
+  return BuildCompoundLiteralExpr(litLParenLoc, TInfo, litRParenLoc, initE);
 }
 
 /// This is not an AltiVec-style cast or or C++ direct-initialization, so turn
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to