From: Richard Smith Date: Wed, 1 Aug 2018 02:27:18 +0000 (+0000) Subject: Work around GCC miscompile exposed by r338464. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ee75be310d5b62315471e38e63603e7c5b5136f;p=clang Work around GCC miscompile exposed by r338464. See gcc.gnu.org/PR86769 for details of the bug. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338478 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index eb76b949af..b92d76ad42 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6011,9 +6011,12 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) { // Check the attributes on the function type, if any. if (const auto *FD = dyn_cast(&ND)) { + // Don't declare this variable in the second operand of the for-statement; + // GCC miscompiles that by ending its lifetime before evaluating the + // third operand. See gcc.gnu.org/PR86769. + AttributedTypeLoc ATL; for (TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc(); - auto ATL = TL ? TL.getAsAdjusted() - : AttributedTypeLoc(); + (ATL = TL.getAsAdjusted()); TL = ATL.getModifiedLoc()) { // The [[lifetimebound]] attribute can be applied to the implicit object // parameter of a non-static member function (other than a ctor or dtor)