Skip to content

Commit 7032e41

Browse files
mstorsjoronlieb
authored andcommitted
Revert "[clang] Limit lifetimes of temporaries to the full expression (llvm#170517)"
This reverts commit 5daad5b. That commit caused broken compilation for some cases, see llvm#170517 (comment).
1 parent 26b171f commit 7032e41

File tree

10 files changed

+1
-261
lines changed

10 files changed

+1
-261
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ Potentially Breaking Changes
8686
options-related code has been moved out of the Driver into a separate library.
8787
- The ``clangFrontend`` library no longer depends on ``clangDriver``, which may
8888
break downstream projects that relied on this transitive dependency.
89-
- Clang is now more precise with regards to the lifetime of temporary objects
90-
such as when aggregates are passed by value to a function, resulting in
91-
better sharing of stack slots and reduced stack usage. This change can lead
92-
to use-after-scope related issues in code that unintentionally relied on the
93-
previous behavior. If recompiling with ``-fsanitize=address`` shows a
94-
use-after-scope warning, then this is likely the case, and the report printed
95-
should be able to help users pinpoint where the use-after-scope is occurring.
96-
Users can use ``-Xclang -sloppy-temporary-lifetimes`` to retain the old
97-
behavior until they are able to find and resolve issues in their code.
9889

9990
C/C++ Language Potentially Breaking Changes
10091
-------------------------------------------

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,6 @@ ENUM_CODEGENOPT(ZeroCallUsedRegs, ZeroCallUsedRegsKind,
475475
/// non-deleting destructors. (No effect on Microsoft ABI.)
476476
CODEGENOPT(CtorDtorReturnThis, 1, 0, Benign)
477477

478-
/// Set via -Xclang -sloppy-temporary-lifetimes to disable emission of lifetime
479-
/// marker intrinsic calls.
480-
CODEGENOPT(NoLifetimeMarkersForTemporaries, 1, 0, Benign)
481-
482478
/// Enables emitting Import Call sections on supported targets that can be used
483479
/// by the Windows kernel to enable import call optimization.
484480
CODEGENOPT(ImportCallOptimization, 1, 0, Benign)

clang/include/clang/Options/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8317,11 +8317,6 @@ def import_call_optimization : Flag<["-"], "import-call-optimization">,
83178317
def replaceable_function: Joined<["-"], "loader-replaceable-function=">,
83188318
MarshallingInfoStringVector<CodeGenOpts<"LoaderReplaceableFunctionNames">>;
83198319

8320-
def sloppy_temporary_lifetimes
8321-
: Flag<["-"], "sloppy-temporary-lifetimes">,
8322-
HelpText<"Don't emit lifetime markers for temporary objects">,
8323-
MarshallingInfoFlag<CodeGenOpts<"NoLifetimeMarkersForTemporaries">>;
8324-
83258320
} // let Visibility = [CC1Option]
83268321

83278322
//===----------------------------------------------------------------------===//

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4972,27 +4972,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
49724972
return;
49734973
}
49744974

4975-
AggValueSlot ArgSlot = AggValueSlot::ignored();
4976-
// For arguments with aggregate type, create an alloca to store
4977-
// the value. If the argument's type has a destructor, that destructor
4978-
// will run at the end of the full-expression; emit matching lifetime
4979-
// markers.
4980-
//
4981-
// FIXME: For types which don't have a destructor, consider using a
4982-
// narrower lifetime bound.
4983-
if (hasAggregateEvaluationKind(E->getType())) {
4984-
RawAddress ArgSlotAlloca = Address::invalid();
4985-
ArgSlot = CreateAggTemp(E->getType(), "agg.tmp", &ArgSlotAlloca);
4986-
4987-
// Emit a lifetime start/end for this temporary at the end of the full
4988-
// expression.
4989-
if (!CGM.getCodeGenOpts().NoLifetimeMarkersForTemporaries &&
4990-
EmitLifetimeStart(ArgSlotAlloca.getPointer()))
4991-
pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker,
4992-
ArgSlotAlloca);
4993-
}
4994-
4995-
args.add(EmitAnyExpr(E, ArgSlot), type);
4975+
args.add(EmitAnyExprToTemp(E), type);
49964976
}
49974977

49984978
QualType CodeGenFunction::getVarArgType(const Expr *Arg) {

clang/test/CodeGen/lifetime-call-temp.c

Lines changed: 0 additions & 98 deletions
This file was deleted.

clang/test/CodeGen/lifetime-invoke-c.c

Lines changed: 0 additions & 50 deletions
This file was deleted.

clang/test/CodeGenCXX/aggregate-lifetime-invoke.cpp

Lines changed: 0 additions & 47 deletions
This file was deleted.

clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cc

Lines changed: 0 additions & 19 deletions
This file was deleted.

clang/test/CodeGenCXX/stack-reuse-miscompile.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ const char * f(S s)
2626
// CHECK: [[T2:%.*]] = alloca %class.T, align 4
2727
// CHECK: [[T3:%.*]] = alloca %class.T, align 4
2828
//
29-
// CHECK: [[AGG:%.*]] = alloca %class.S, align 4
30-
//
3129
// FIXME: We could defer starting the lifetime of the return object of concat
3230
// until the call.
3331
// CHECK: call void @llvm.lifetime.start.p0(ptr [[T1]])
@@ -36,12 +34,10 @@ const char * f(S s)
3634
// CHECK: [[T4:%.*]] = call noundef ptr @_ZN1TC1EPKc(ptr {{[^,]*}} [[T2]], ptr noundef @.str)
3735
//
3836
// CHECK: call void @llvm.lifetime.start.p0(ptr [[T3]])
39-
// CHECK: call void @llvm.lifetime.start.p0(ptr [[AGG]])
4037
// CHECK: [[T5:%.*]] = call noundef ptr @_ZN1TC1E1S(ptr {{[^,]*}} [[T3]], [2 x i32] %{{.*}})
4138
//
4239
// CHECK: call void @_ZNK1T6concatERKS_(ptr dead_on_unwind writable sret(%class.T) align 4 [[T1]], ptr {{[^,]*}} [[T2]], ptr noundef nonnull align 4 dereferenceable(16) [[T3]])
4340
// CHECK: [[T6:%.*]] = call noundef ptr @_ZNK1T3strEv(ptr {{[^,]*}} [[T1]])
44-
// CHECK: call void @llvm.lifetime.end.p0(ptr [[AGG]])
4541
//
4642
// CHECK: call void @llvm.lifetime.end.p0(
4743
// CHECK: call void @llvm.lifetime.end.p0(

clang/test/CodeGenCoroutines/pr59181.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void foo() {
4949
}
5050

5151
// CHECK: cleanup.cont:{{.*}}
52-
// CHECK-NEXT: call void @llvm.lifetime.start.p0(ptr [[AGG:%agg.tmp]])
5352
// CHECK-NEXT: load i8
5453
// CHECK-NEXT: trunc
5554
// CHECK-NEXT: store i1 false
@@ -58,6 +57,3 @@ void foo() {
5857
// CHECK-NOT: call void @llvm.lifetime
5958
// CHECK: call void @llvm.coro.await.suspend.void(
6059
// CHECK-NEXT: %{{[0-9]+}} = call i8 @llvm.coro.suspend(
61-
62-
// CHECK-LABEL: cond.end:
63-
// check call @llvm.lifetime.end.p0(ptr [[AGG]])

0 commit comments

Comments
 (0)