r174339 - PR15095: Use more correct source locations for the InitListExpr we fake up for
Richard Smith
richard-llvm at metafoo.co.uk
Mon Feb 4 21:55:58 PST 2013
Author: rsmith
Date: Mon Feb 4 23:55:57 2013
New Revision: 174339
URL: http://llvm.org/viewvc/llvm-project?rev=174339&view=rev
Log:
PR15095: Use more correct source locations for the InitListExpr we fake up for
vector initialization. Patch by John Stratton!
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/unittests/AST/MatchVerifier.h
cfe/trunk/unittests/AST/SourceLocationTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=174339&r1=174338&r2=174339&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Feb 4 23:55:57 2013
@@ -922,6 +922,16 @@ const internal::VariadicDynCastAllOfMatc
Stmt,
UserDefinedLiteral> userDefinedLiteral;
+/// \brief Matches compound (i.e. non-scalar) literals
+///
+/// Example match: {1}, (1, 2)
+/// \code
+/// int array[4] = {1}; vector int myvec = (vector int)(1, 2);
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+ Stmt,
+ CompoundLiteralExpr> compoundLiteralExpr;
+
/// \brief Matches nullptr literal.
const internal::VariadicDynCastAllOfMatcher<
Stmt,
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=174339&r1=174338&r2=174339&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Feb 4 23:55:57 2013
@@ -4627,10 +4627,15 @@ ExprResult Sema::BuildVectorLiteral(Sour
Expr **exprs;
unsigned numExprs;
Expr *subExpr;
+ SourceLocation LiteralLParenLoc, LiteralRParenLoc;
if (ParenListExpr *PE = dyn_cast<ParenListExpr>(E)) {
+ LiteralLParenLoc = PE->getLParenLoc();
+ LiteralRParenLoc = PE->getRParenLoc();
exprs = PE->getExprs();
numExprs = PE->getNumExprs();
- } else {
+ } else { // isa<ParenExpr> by assertion at function entrance
+ LiteralLParenLoc = cast<ParenExpr>(E)->getLParen();
+ LiteralRParenLoc = cast<ParenExpr>(E)->getRParen();
subExpr = cast<ParenExpr>(E)->getSubExpr();
exprs = &subExpr;
numExprs = 1;
@@ -4687,8 +4692,8 @@ ExprResult Sema::BuildVectorLiteral(Sour
}
// 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, LiteralLParenLoc,
+ initExprs, LiteralRParenLoc);
initE->setType(Ty);
return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, initE);
}
Modified: cfe/trunk/unittests/AST/MatchVerifier.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/MatchVerifier.h?rev=174339&r1=174338&r2=174339&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/MatchVerifier.h (original)
+++ cfe/trunk/unittests/AST/MatchVerifier.h Mon Feb 4 23:55:57 2013
@@ -25,7 +25,7 @@
namespace clang {
namespace ast_matchers {
-enum Language { Lang_C, Lang_C89, Lang_CXX };
+enum Language { Lang_C, Lang_C89, Lang_CXX, Lang_OpenCL };
/// \brief Base class for verifying some property of nodes found by a matcher.
template <typename NodeType>
@@ -85,6 +85,8 @@ testing::AssertionResult MatchVerifier<N
Args.push_back("-std=c++98");
FileName = "input.cc";
break;
+ case Lang_OpenCL:
+ FileName = "input.cl";
}
// Default to failure in case callback is never called
Modified: cfe/trunk/unittests/AST/SourceLocationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/SourceLocationTest.cpp?rev=174339&r1=174338&r2=174339&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/SourceLocationTest.cpp (original)
+++ cfe/trunk/unittests/AST/SourceLocationTest.cpp Mon Feb 4 23:55:57 2013
@@ -122,5 +122,38 @@ TEST(CXXConstructorDecl, NoRetFunTypeLoc
EXPECT_TRUE(Verifier.match("class C { C(); };", functionDecl()));
}
+TEST(CompoundLiteralExpr, CompoundVectorLiteralRange) {
+ RangeVerifier<CompoundLiteralExpr> Verifier;
+ Verifier.expectRange(2, 11, 2, 22);
+ EXPECT_TRUE(Verifier.match(
+ "typedef int int2 __attribute__((ext_vector_type(2)));\n"
+ "int2 i2 = (int2){1, 2};", compoundLiteralExpr()));
+}
+
+TEST(CompoundLiteralExpr, ParensCompoundVectorLiteralRange) {
+ RangeVerifier<CompoundLiteralExpr> Verifier;
+ Verifier.expectRange(2, 11, 2, 22);
+ EXPECT_TRUE(Verifier.match(
+ "typedef int int2 __attribute__((ext_vector_type(2)));\n"
+ "int2 i2 = (int2)(1, 2);",
+ compoundLiteralExpr(), Lang_OpenCL));
+}
+
+TEST(InitListExpr, VectorLiteralListBraceRange) {
+ RangeVerifier<InitListExpr> Verifier;
+ Verifier.expectRange(2, 17, 2, 22);
+ EXPECT_TRUE(Verifier.match(
+ "typedef int int2 __attribute__((ext_vector_type(2)));\n"
+ "int2 i2 = (int2){1, 2};", initListExpr()));
+}
+
+TEST(InitListExpr, VectorLiteralInitListParens) {
+ RangeVerifier<InitListExpr> Verifier;
+ Verifier.expectRange(2, 17, 2, 22);
+ EXPECT_TRUE(Verifier.match(
+ "typedef int int2 __attribute__((ext_vector_type(2)));\n"
+ "int2 i2 = (int2)(1, 2);", initListExpr(), Lang_OpenCL));
+}
+
} // end namespace ast_matchers
} // end namespace clang
More information about the cfe-commits
mailing list