Skip to content

Commit 5b6dbde

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

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
@@ -361,17 +361,18 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
361361
bool HasOnlyLifetimeMarkers =
362362
HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
363363
bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
364+
365+
std::optional<ApplyDebugLocation> OAL;
364366
if (HasCleanups) {
365367
// Make sure the line table doesn't jump back into the body for
366368
// the ret after it's been at EndLoc.
367-
std::optional<ApplyDebugLocation> AL;
368369
if (CGDebugInfo *DI = getDebugInfo()) {
369370
if (OnlySimpleReturnStmts)
370371
DI->EmitLocation(Builder, EndLoc);
371372
else
372373
// We may not have a valid end location. Try to apply it anyway, and
373374
// fall back to an artificial location if needed.
374-
AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
375+
OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
375376
}
376377

377378
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)