Work around more GCC miscompiles exposed by r338464.
authorMartin Storsjo <martin@martin.st>
Thu, 2 Aug 2018 18:12:08 +0000 (18:12 +0000)
committerMartin Storsjo <martin@martin.st>
Thu, 2 Aug 2018 18:12:08 +0000 (18:12 +0000)
This is the same fix as in r338478, for another occurrance of the
same pattern from r338464.

See gcc.gnu.org/PR86769 for details of the bug.

llvm-svn: 338749

clang/lib/Sema/SemaInit.cpp

index f006a67..01ef86c 100644 (file)
@@ -6371,8 +6371,12 @@ static bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD) {
   const TypeSourceInfo *TSI = FD->getTypeSourceInfo();
   if (!TSI)
     return false;
+  // 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 = TSI->getTypeLoc();
-       auto ATL = TL.getAsAdjusted<AttributedTypeLoc>();
+       (ATL = TL.getAsAdjusted<AttributedTypeLoc>());
        TL = ATL.getModifiedLoc()) {
     if (ATL.getAttrKind() == AttributedType::attr_lifetimebound)
       return true;