Skip to content

Commit 8c46bfa

Browse files
committed
[CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended
rdar://103570533 Differential Revision: https://reviews.llvm.org/D142243
1 parent d7c7941 commit 8c46bfa

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,18 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
357357
bool HasOnlyLifetimeMarkers =
358358
HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
359359
bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
360+
361+
Optional<ApplyDebugLocation> OAL;
360362
if (HasCleanups) {
361363
// Make sure the line table doesn't jump back into the body for
362364
// the ret after it's been at EndLoc.
363-
Optional<ApplyDebugLocation> AL;
364365
if (CGDebugInfo *DI = getDebugInfo()) {
365366
if (OnlySimpleReturnStmts)
366367
DI->EmitLocation(Builder, EndLoc);
367368
else
368369
// We may not have a valid end location. Try to apply it anyway, and
369370
// fall back to an artificial location if needed.
370-
AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
371+
OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
371372
}
372373

373374
PopCleanupBlocks(PrologueCleanupDepth);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc -std=gnu99 -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
2+
3+
@interface NSString
4+
@end
5+
6+
struct A {
7+
NSString *a;
8+
};
9+
10+
NSString* _Nonnull foo()
11+
{
12+
struct A a;
13+
return 0;
14+
}

0 commit comments

Comments
 (0)