aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprAgg.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2024-06-12 13:14:26 -0700
committerGitHub <noreply@github.com>2024-06-12 13:14:26 -0700
commit682d461d5a231cee54d65910e6341769419a67d7 (patch)
tree1441fb2956b5f3c2f355d442c4de0508f5259a35 /clang/lib/CodeGen/CGExprAgg.cpp
parent294f3ce5dde916c358d8f672b4a1c706c0387154 (diff)
downloadllvm-682d461d5a231cee54d65910e6341769419a67d7.zip
llvm-682d461d5a231cee54d65910e6341769419a67d7.tar.gz
llvm-682d461d5a231cee54d65910e6341769419a67d7.tar.bz2
Revert "✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy)" (#95299)
Reverts llvm/llvm-project#68620 Introduce or expose a memory leak and UB, see llvm/llvm-project#68620
Diffstat (limited to 'clang/lib/CodeGen/CGExprAgg.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp40
1 files changed, 8 insertions, 32 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index a8bb254..b2a5cee 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -509,16 +509,6 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
uint64_t NumInitElements = Args.size();
uint64_t NumArrayElements = AType->getNumElements();
- for (const auto *Init : Args) {
- if (const auto *Embed = dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts())) {
- NumInitElements += Embed->getDataElementCount() - 1;
- if (NumInitElements > NumArrayElements) {
- NumInitElements = NumArrayElements;
- break;
- }
- }
- }
-
assert(NumInitElements <= NumArrayElements);
QualType elementType =
@@ -587,37 +577,23 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
llvm::Value *one = llvm::ConstantInt::get(CGF.SizeTy, 1);
- auto Emit = [&](Expr *Init, uint64_t ArrayIndex) {
+ // Emit the explicit initializers.
+ for (uint64_t i = 0; i != NumInitElements; ++i) {
llvm::Value *element = begin;
- if (ArrayIndex > 0) {
- element = Builder.CreateInBoundsGEP(
- llvmElementType, begin,
- llvm::ConstantInt::get(CGF.SizeTy, ArrayIndex), "arrayinit.element");
+ if (i > 0) {
+ element = Builder.CreateInBoundsGEP(llvmElementType, begin,
+ llvm::ConstantInt::get(CGF.SizeTy, i),
+ "arrayinit.element");
// Tell the cleanup that it needs to destroy up to this
// element. TODO: some of these stores can be trivially
// observed to be unnecessary.
- if (endOfInit.isValid())
- Builder.CreateStore(element, endOfInit);
+ if (endOfInit.isValid()) Builder.CreateStore(element, endOfInit);
}
LValue elementLV = CGF.MakeAddrLValue(
Address(element, llvmElementType, elementAlign), elementType);
- EmitInitializationToLValue(Init, elementLV);
- return true;
- };
-
- unsigned ArrayIndex = 0;
- // Emit the explicit initializers.
- for (uint64_t i = 0; i != NumInitElements; ++i) {
- if (ArrayIndex >= NumInitElements)
- break;
- if (auto *EmbedS = dyn_cast<EmbedExpr>(Args[i]->IgnoreParenImpCasts())) {
- EmbedS->doForEachDataElement(Emit, ArrayIndex);
- } else {
- Emit(Args[i], ArrayIndex);
- ArrayIndex++;
- }
+ EmitInitializationToLValue(Args[i], elementLV);
}
// Check whether there's a non-trivial array-fill expression.