r339730 - Fix Stmt::ignoreImplicit
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 15 05:18:28 PDT 2018
I believe the compile is correct on it's own, it's the double compile with -E and of that preprocessed files that goes wrong. i.e something like:
https://godbolt.org/g/fsXjB7
We hit it every now and again because of the use of ccache.
Cheers,
Dave
________________________________________
From: Stephen Kelly <steveire at gmail.com>
Sent: 15 August 2018 13:05:09
To: David Green
Cc: llvm-commits; nd
Subject: Re: r339730 - Fix Stmt::ignoreImplicit
I tried on godbolt and your example works with GCC 4.9 and later.
https://godbolt.org/beta/z/MjE4ZT
Something else may have been wrong in addition.
Thanks,
Stephen.
On Wed, 15 Aug 2018, 12:48 David Green, <David.Green at arm.com<mailto:David.Green at arm.com>> wrote:
Anything before GCC 8 I believe (although I found the error with GCC 4.9). It incorrectly turns code like this:
void func(const char *);
#define MACRO(X) func(#X)
MACRO(R"(Hello
this is a string)");
with -E into:
func("R\"(Hello
this is a string)\""
);
GCC 8 (and clang) get it right by changing it to:
func("R\"(Hello\nthis is a string)\"")
Dave
From: Stephen Kelly <steveire at gmail.com<mailto:steveire at gmail.com>>
Sent: 15 August 2018 12:31
To: David Green
Cc: llvm-commits; nd
Subject: Re: r339730 - Fix Stmt::ignoreImplicit
Great, thanks for that!
Can you say what version of GCC is affected?
Thanks,
Stephen.
On Wed, 15 Aug 2018, 11:44 David Green, <David.Green at arm.com<mailto:David.Green at arm.com><mailto:David.Green at arm.com<mailto:David.Green at arm.com>>> wrote:
Hello
Some version of GCC don't like raw string literals inside macro's.
I've put up https://reviews.llvm.org/rL339759 as a fix. Let me know if it looks iffy.
Cheers
Dave
________________________________________
From: cfe-commits <cfe-commits-bounces at lists.llvm.org<mailto:cfe-commits-bounces at lists.llvm.org><mailto:cfe-commits-bounces at lists.llvm.org<mailto:cfe-commits-bounces at lists.llvm.org>>> on behalf of Stephen Kelly via cfe-commits <cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org><mailto:cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>>>
Sent: 14 August 2018 22:33:28
To: cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org><mailto:cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>>
Subject: r339730 - Fix Stmt::ignoreImplicit
Author: steveire
Date: Tue Aug 14 14:33:28 2018
New Revision: 339730
URL: http://llvm.org/viewvc/llvm-project?rev=339730&view=rev
Log:
Fix Stmt::ignoreImplicit
Summary:
A CXXBindTemporaryExpr can appear inside an ImplicitCastExpr, and was
not ignored previously.
Fixes the case reported in PR37327.
Reviewers: rsmith, dblaikie, klimek
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D50666
Modified:
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=339730&r1=339729&r2=339730&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Tue Aug 14 14:33:28 2018
@@ -113,17 +113,23 @@ void Stmt::EnableStatistics() {
Stmt *Stmt::IgnoreImplicit() {
Stmt *s = this;
- if (auto *ewc = dyn_cast<ExprWithCleanups>(s))
- s = ewc->getSubExpr();
+ Stmt *lasts = nullptr;
- if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s))
- s = mte->GetTemporaryExpr();
+ while (s != lasts) {
+ lasts = s;
- if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s))
- s = bte->getSubExpr();
+ if (auto *ewc = dyn_cast<ExprWithCleanups>(s))
+ s = ewc->getSubExpr();
- while (auto *ice = dyn_cast<ImplicitCastExpr>(s))
- s = ice->getSubExpr();
+ if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s))
+ s = mte->GetTemporaryExpr();
+
+ if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s))
+ s = bte->getSubExpr();
+
+ if (auto *ice = dyn_cast<ImplicitCastExpr>(s))
+ s = ice->getSubExpr();
+ }
return s;
}
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=339730&r1=339729&r2=339730&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Tue Aug 14 14:33:28 2018
@@ -1321,6 +1321,45 @@ TEST(IgnoringImplicit, MatchesImplicit)
varDecl(has(ignoringImplicit(cxxConstructExpr())))));
}
+TEST(IgnoringImplicit, MatchesNestedImplicit) {
+ EXPECT_TRUE(matches(R"(
+
+struct OtherType;
+
+struct SomeType
+{
+ SomeType() {}
+ SomeType(const OtherType&) {}
+ SomeType& operator=(OtherType const&) { return *this; }
+};
+
+struct OtherType
+{
+ OtherType() {}
+ ~OtherType() {}
+};
+
+OtherType something()
+{
+ return {};
+}
+
+int main()
+{
+ SomeType i = something();
+}
+)"
+ , varDecl(
+ hasName("i"),
+ hasInitializer(exprWithCleanups(has(
+ cxxConstructExpr(has(expr(ignoringImplicit(cxxConstructExpr(
+ has(expr(ignoringImplicit(callExpr())))
+ )))))
+ )))
+ )
+ ));
+}
+
TEST(IgnoringImplicit, DoesNotMatchIncorrectly) {
EXPECT_TRUE(
notMatches("class C {}; C a = C();", varDecl(has(cxxConstructExpr()))));
_______________________________________________
cfe-commits mailing list
cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org><mailto:cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the llvm-commits
mailing list