Author: Timm Bäder Date: 2024-06-13T15:31:24+02:00 New Revision: ae73706075bb2ea4bbc87c4b33f3b681555f8dfb
URL: https://github.com/llvm/llvm-project/commit/ae73706075bb2ea4bbc87c4b33f3b681555f8dfb DIFF: https://github.com/llvm/llvm-project/commit/ae73706075bb2ea4bbc87c4b33f3b681555f8dfb.diff LOG: [clang][Interp] Fix references to objects The previous commit tried to handle this in a way that's too general. Move the !Initializing case down to the array type. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/SemaCXX/cxx0x-initializer-references.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 60b1e089e74a6..b8e32452371a4 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1107,23 +1107,6 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits, return this->delegate(Inits[0]); } - // Prepare composite return value. - if (!Initializing) { - if (GlobalDecl) { - std::optional<unsigned> GlobalIndex = P.createGlobal(E); - if (!GlobalIndex) - return false; - if (!this->emitGetPtrGlobal(*GlobalIndex, E)) - return false; - } else { - std::optional<unsigned> LocalIndex = allocateLocal(E); - if (!LocalIndex) - return false; - if (!this->emitGetPtrGlobal(*LocalIndex, E)) - return false; - } - } - QualType T = E->getType(); if (T->isRecordType()) { const Record *R = getRecord(E->getType()); @@ -1224,6 +1207,23 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits, } if (T->isArrayType()) { + // Prepare composite return value. + if (!Initializing) { + if (GlobalDecl) { + std::optional<unsigned> GlobalIndex = P.createGlobal(E); + if (!GlobalIndex) + return false; + if (!this->emitGetPtrGlobal(*GlobalIndex, E)) + return false; + } else { + std::optional<unsigned> LocalIndex = allocateLocal(E); + if (!LocalIndex) + return false; + if (!this->emitGetPtrLocal(*LocalIndex, E)) + return false; + } + } + unsigned ElementIndex = 0; for (const Expr *Init : Inits) { if (!this->visitArrayElemInit(ElementIndex, Init)) diff --git a/clang/test/SemaCXX/cxx0x-initializer-references.cpp b/clang/test/SemaCXX/cxx0x-initializer-references.cpp index 0f816a39f2ba0..f0018966e7e71 100644 --- a/clang/test/SemaCXX/cxx0x-initializer-references.cpp +++ b/clang/test/SemaCXX/cxx0x-initializer-references.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter struct one { char c; }; struct two { char c[2]; }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits