Skip to content

Commit 2958976

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:cbed9a64491d82d6c4a3a7d0cd97cdee32ff2301 into amd-gfx:fcac22e68cfc
Local branch amd-gfx fcac22e Merged main:ea20647023f7bb110e8a198485727458684c43c6 into amd-gfx:bd7ba70d3543 Remote branch main cbed9a6 [clang][Interp] Fix ignoring assumptions
2 parents fcac22e + cbed9a6 commit 2958976

File tree

52 files changed

+392
-680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+392
-680
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ class Interpreter {
110110
RuntimeInterfaceBuilder::TransformExprFunction *AddPrintValueCall = nullptr;
111111

112112
protected:
113-
// Derived classes can make use an extended interface of the Interpreter.
114-
// That's useful for testing and out-of-tree clients.
115-
Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err);
113+
// Derived classes can use an extended interface of the Interpreter.
114+
Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err,
115+
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr);
116116

117117
// Create the internal IncrementalExecutor, or re-create it after calling
118118
// ResetExecutor().
@@ -128,13 +128,6 @@ class Interpreter {
128128
// custom runtime.
129129
virtual std::unique_ptr<RuntimeInterfaceBuilder> FindRuntimeInterface();
130130

131-
// Lazily construct thev ORCv2 JITBuilder. This called when the internal
132-
// IncrementalExecutor is created. The default implementation populates an
133-
// in-process JIT with debugging support. Override this to configure the JIT
134-
// engine used for execution.
135-
virtual llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>>
136-
CreateJITBuilder(CompilerInstance &CI);
137-
138131
public:
139132
virtual ~Interpreter();
140133

@@ -189,6 +182,8 @@ class Interpreter {
189182
llvm::DenseMap<CXXRecordDecl *, llvm::orc::ExecutorAddr> Dtors;
190183

191184
llvm::SmallVector<Expr *, 4> ValuePrintingInfo;
185+
186+
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder;
192187
};
193188
} // namespace clang
194189

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -687,26 +687,29 @@ bool ByteCodeStmtGen<Emitter>::visitDefaultStmt(const DefaultStmt *S) {
687687
template <class Emitter>
688688
bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) {
689689

690-
for (const Attr *A : S->getAttrs()) {
691-
auto *AA = dyn_cast<CXXAssumeAttr>(A);
692-
if (!AA)
693-
continue;
690+
if (this->Ctx.getLangOpts().CXXAssumptions &&
691+
!this->Ctx.getLangOpts().MSVCCompat) {
692+
for (const Attr *A : S->getAttrs()) {
693+
auto *AA = dyn_cast<CXXAssumeAttr>(A);
694+
if (!AA)
695+
continue;
694696

695-
assert(isa<NullStmt>(S->getSubStmt()));
697+
assert(isa<NullStmt>(S->getSubStmt()));
696698

697-
const Expr *Assumption = AA->getAssumption();
698-
if (Assumption->isValueDependent())
699-
return false;
699+
const Expr *Assumption = AA->getAssumption();
700+
if (Assumption->isValueDependent())
701+
return false;
700702

701-
if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
702-
continue;
703+
if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
704+
continue;
703705

704-
// Evaluate assumption.
705-
if (!this->visitBool(Assumption))
706-
return false;
706+
// Evaluate assumption.
707+
if (!this->visitBool(Assumption))
708+
return false;
707709

708-
if (!this->emitAssume(Assumption))
709-
return false;
710+
if (!this->emitAssume(Assumption))
711+
return false;
712+
}
710713
}
711714

712715
// Ignore other attributes.

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,19 +2227,10 @@ void Generic_GCC::GCCInstallationDetector::init(
22272227
SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
22282228
// Add some triples that we want to check first.
22292229
CandidateTripleAliases.push_back(TargetTriple.str());
2230-
std::string TripleNoVendor, BiarchTripleNoVendor;
2231-
if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor) {
2232-
StringRef OSEnv = TargetTriple.getOSAndEnvironmentName();
2233-
if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32)
2234-
OSEnv = "linux-gnu";
2235-
TripleNoVendor = (TargetTriple.getArchName().str() + '-' + OSEnv).str();
2230+
std::string TripleNoVendor = TargetTriple.getArchName().str() + "-" +
2231+
TargetTriple.getOSAndEnvironmentName().str();
2232+
if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor)
22362233
CandidateTripleAliases.push_back(TripleNoVendor);
2237-
if (BiarchVariantTriple.getArch() != llvm::Triple::UnknownArch) {
2238-
BiarchTripleNoVendor =
2239-
(BiarchVariantTriple.getArchName().str() + '-' + OSEnv).str();
2240-
CandidateBiarchTripleAliases.push_back(BiarchTripleNoVendor);
2241-
}
2242-
}
22432234

22442235
CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
22452236
CandidateTripleAliases, CandidateBiarchLibDirs,
@@ -2462,9 +2453,11 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
24622453
// lists should shrink over time. Please don't add more elements to *Triples.
24632454
static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
24642455
static const char *const AArch64Triples[] = {
2465-
"aarch64-none-linux-gnu", "aarch64-redhat-linux", "aarch64-suse-linux"};
2456+
"aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
2457+
"aarch64-suse-linux"};
24662458
static const char *const AArch64beLibDirs[] = {"/lib"};
2467-
static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu"};
2459+
static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
2460+
"aarch64_be-linux-gnu"};
24682461

24692462
static const char *const ARMLibDirs[] = {"/lib"};
24702463
static const char *const ARMTriples[] = {"arm-linux-gnueabi"};
@@ -2486,44 +2479,47 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
24862479

24872480
static const char *const X86_64LibDirs[] = {"/lib64", "/lib"};
24882481
static const char *const X86_64Triples[] = {
2489-
"x86_64-unknown-linux-gnu", "x86_64-pc-linux-gnu",
2490-
"x86_64-redhat-linux6E", "x86_64-redhat-linux",
2491-
"x86_64-suse-linux", "x86_64-manbo-linux-gnu",
2492-
"x86_64-slackware-linux", "x86_64-unknown-linux",
2482+
"x86_64-linux-gnu", "x86_64-unknown-linux-gnu",
2483+
"x86_64-pc-linux-gnu", "x86_64-redhat-linux6E",
2484+
"x86_64-redhat-linux", "x86_64-suse-linux",
2485+
"x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
2486+
"x86_64-slackware-linux", "x86_64-unknown-linux",
24932487
"x86_64-amazon-linux"};
24942488
static const char *const X32Triples[] = {"x86_64-linux-gnux32",
24952489
"x86_64-pc-linux-gnux32"};
24962490
static const char *const X32LibDirs[] = {"/libx32", "/lib"};
24972491
static const char *const X86LibDirs[] = {"/lib32", "/lib"};
24982492
static const char *const X86Triples[] = {
2499-
"i686-linux-gnu", "i686-pc-linux-gnu", "i386-redhat-linux6E",
2500-
"i686-redhat-linux", "i386-redhat-linux", "i586-suse-linux",
2501-
"i686-montavista-linux",
2493+
"i586-linux-gnu", "i686-linux-gnu", "i686-pc-linux-gnu",
2494+
"i386-redhat-linux6E", "i686-redhat-linux", "i386-redhat-linux",
2495+
"i586-suse-linux", "i686-montavista-linux",
25022496
};
25032497

25042498
static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
25052499
static const char *const LoongArch64Triples[] = {
25062500
"loongarch64-linux-gnu", "loongarch64-unknown-linux-gnu"};
25072501

25082502
static const char *const M68kLibDirs[] = {"/lib"};
2509-
static const char *const M68kTriples[] = {"m68k-unknown-linux-gnu",
2510-
"m68k-suse-linux"};
2503+
static const char *const M68kTriples[] = {
2504+
"m68k-linux-gnu", "m68k-unknown-linux-gnu", "m68k-suse-linux"};
25112505

25122506
static const char *const MIPSLibDirs[] = {"/libo32", "/lib"};
25132507
static const char *const MIPSTriples[] = {
25142508
"mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu",
25152509
"mips-img-linux-gnu", "mipsisa32r6-linux-gnu"};
25162510
static const char *const MIPSELLibDirs[] = {"/libo32", "/lib"};
2517-
static const char *const MIPSELTriples[] = {"mipsel-linux-gnu",
2518-
"mips-img-linux-gnu"};
2511+
static const char *const MIPSELTriples[] = {
2512+
"mipsel-linux-gnu", "mips-img-linux-gnu", "mipsisa32r6el-linux-gnu"};
25192513

25202514
static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"};
25212515
static const char *const MIPS64Triples[] = {
2522-
"mips-mti-linux-gnu", "mips-img-linux-gnu", "mips64-linux-gnuabi64",
2516+
"mips64-linux-gnu", "mips-mti-linux-gnu",
2517+
"mips-img-linux-gnu", "mips64-linux-gnuabi64",
25232518
"mipsisa64r6-linux-gnu", "mipsisa64r6-linux-gnuabi64"};
25242519
static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"};
25252520
static const char *const MIPS64ELTriples[] = {
2526-
"mips-mti-linux-gnu", "mips-img-linux-gnu", "mips64el-linux-gnuabi64",
2521+
"mips64el-linux-gnu", "mips-mti-linux-gnu",
2522+
"mips-img-linux-gnu", "mips64el-linux-gnuabi64",
25272523
"mipsisa64r6el-linux-gnu", "mipsisa64r6el-linux-gnuabi64"};
25282524

25292525
static const char *const MIPSN32LibDirs[] = {"/lib32"};
@@ -2538,39 +2534,46 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
25382534

25392535
static const char *const PPCLibDirs[] = {"/lib32", "/lib"};
25402536
static const char *const PPCTriples[] = {
2541-
"powerpc-unknown-linux-gnu",
2537+
"powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe",
25422538
// On 32-bit PowerPC systems running SUSE Linux, gcc is configured as a
25432539
// 64-bit compiler which defaults to "-m32", hence "powerpc64-suse-linux".
25442540
"powerpc64-suse-linux", "powerpc-montavista-linuxspe"};
25452541
static const char *const PPCLELibDirs[] = {"/lib32", "/lib"};
2546-
static const char *const PPCLETriples[] = {"powerpcle-unknown-linux-gnu",
2542+
static const char *const PPCLETriples[] = {"powerpcle-linux-gnu",
2543+
"powerpcle-unknown-linux-gnu",
25472544
"powerpcle-linux-musl"};
25482545

25492546
static const char *const PPC64LibDirs[] = {"/lib64", "/lib"};
2550-
static const char *const PPC64Triples[] = {"powerpc64-unknown-linux-gnu",
2551-
"powerpc64-suse-linux",
2552-
"ppc64-redhat-linux"};
2547+
static const char *const PPC64Triples[] = {
2548+
"powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu",
2549+
"powerpc64-suse-linux", "ppc64-redhat-linux"};
25532550
static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"};
25542551
static const char *const PPC64LETriples[] = {
2555-
"powerpc64le-unknown-linux-gnu", "powerpc64le-none-linux-gnu",
2556-
"powerpc64le-suse-linux", "ppc64le-redhat-linux"};
2552+
"powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu",
2553+
"powerpc64le-none-linux-gnu", "powerpc64le-suse-linux",
2554+
"ppc64le-redhat-linux"};
25572555

25582556
static const char *const RISCV32LibDirs[] = {"/lib32", "/lib"};
25592557
static const char *const RISCV32Triples[] = {"riscv32-unknown-linux-gnu",
2558+
"riscv32-linux-gnu",
25602559
"riscv32-unknown-elf"};
25612560
static const char *const RISCV64LibDirs[] = {"/lib64", "/lib"};
25622561
static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
2562+
"riscv64-linux-gnu",
25632563
"riscv64-unknown-elf"};
25642564

25652565
static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
2566-
static const char *const SPARCv8Triples[] = {"sparcv8-linux-gnu"};
2566+
static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",
2567+
"sparcv8-linux-gnu"};
25672568
static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"};
2568-
static const char *const SPARCv9Triples[] = {"sparcv9-linux-gnu"};
2569+
static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu",
2570+
"sparcv9-linux-gnu"};
25692571

25702572
static const char *const SystemZLibDirs[] = {"/lib64", "/lib"};
25712573
static const char *const SystemZTriples[] = {
2572-
"s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", "s390x-suse-linux",
2573-
"s390x-redhat-linux"};
2574+
"s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu",
2575+
"s390x-suse-linux", "s390x-redhat-linux"};
2576+
25742577

25752578
using std::begin;
25762579
using std::end;

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,32 @@ IncrementalCompilerBuilder::CreateCudaHost() {
229229
}
230230

231231
Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
232-
llvm::Error &Err) {
233-
llvm::ErrorAsOutParameter EAO(&Err);
232+
llvm::Error &ErrOut,
233+
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder)
234+
: JITBuilder(std::move(JITBuilder)) {
235+
llvm::ErrorAsOutParameter EAO(&ErrOut);
234236
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
235237
TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
236-
IncrParser = std::make_unique<IncrementalParser>(*this, std::move(CI),
237-
*TSCtx->getContext(), Err);
238+
IncrParser = std::make_unique<IncrementalParser>(
239+
*this, std::move(CI), *TSCtx->getContext(), ErrOut);
240+
if (ErrOut)
241+
return;
242+
243+
// Not all frontends support code-generation, e.g. ast-dump actions don't
244+
if (IncrParser->getCodeGen()) {
245+
if (llvm::Error Err = CreateExecutor()) {
246+
ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
247+
return;
248+
}
249+
250+
// Process the PTUs that came from initialization. For example -include will
251+
// give us a header that's processed at initialization of the preprocessor.
252+
for (PartialTranslationUnit &PTU : IncrParser->getPTUs())
253+
if (llvm::Error Err = Execute(PTU)) {
254+
ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
255+
return;
256+
}
257+
}
238258
}
239259

240260
Interpreter::~Interpreter() {
@@ -382,25 +402,29 @@ createJITTargetMachineBuilder(const std::string &TT) {
382402
return llvm::orc::JITTargetMachineBuilder(llvm::Triple(TT));
383403
}
384404

385-
llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>>
386-
Interpreter::CreateJITBuilder(CompilerInstance &CI) {
387-
auto JTMB = createJITTargetMachineBuilder(CI.getTargetOpts().Triple);
388-
if (!JTMB)
389-
return JTMB.takeError();
390-
return IncrementalExecutor::createDefaultJITBuilder(std::move(*JTMB));
391-
}
392-
393405
llvm::Error Interpreter::CreateExecutor() {
394406
if (IncrExecutor)
395407
return llvm::make_error<llvm::StringError>("Operation failed. "
396408
"Execution engine exists",
397409
std::error_code());
398-
llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>> JB =
399-
CreateJITBuilder(*getCompilerInstance());
400-
if (!JB)
401-
return JB.takeError();
410+
if (!IncrParser->getCodeGen())
411+
return llvm::make_error<llvm::StringError>("Operation failed. "
412+
"No code generator available",
413+
std::error_code());
414+
if (!JITBuilder) {
415+
const std::string &TT = getCompilerInstance()->getTargetOpts().Triple;
416+
auto JTMB = createJITTargetMachineBuilder(TT);
417+
if (!JTMB)
418+
return JTMB.takeError();
419+
auto JB = IncrementalExecutor::createDefaultJITBuilder(std::move(*JTMB));
420+
if (!JB)
421+
return JB.takeError();
422+
JITBuilder = std::move(*JB);
423+
}
424+
402425
llvm::Error Err = llvm::Error::success();
403-
auto Executor = std::make_unique<IncrementalExecutor>(*TSCtx, **JB, Err);
426+
auto Executor =
427+
std::make_unique<IncrementalExecutor>(*TSCtx, *JITBuilder, Err);
404428
if (!Err)
405429
IncrExecutor = std::move(Executor);
406430

clang/test/Interpreter/execute.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
// RUN: cat %s | clang-repl | FileCheck %s
99
// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
10+
// RUN: clang-repl -Xcc -include -Xcc %s | FileCheck %s
11+
// RUN: clang-repl -Xcc -fsyntax-only -Xcc -include -Xcc %s
1012
extern "C" int printf(const char *, ...);
1113
int i = 42;
1214
auto r1 = printf("i = %d\n", i);
@@ -19,5 +21,3 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long long
1921

2022
inline int foo() { return 42; }
2123
int r3 = foo();
22-
23-
%quit

clang/test/Interpreter/inline-virtual.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); };
1414
// PartialTranslationUnit.
1515
inline A::~A() { printf("~A(%d)\n", a); }
1616

17-
// Create one instance with new and delete it.
17+
// Create one instance with new and delete it. We crash here now:
1818
A *a1 = new A(1);
1919
delete a1;
2020
// CHECK: ~A(1)

clang/test/SemaCXX/cxx23-assume-disabled.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions -verify
22
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility -verify
3+
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions -fexperimental-new-constant-interpreter -verify
4+
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility -fexperimental-new-constant-interpreter -verify
5+
36
// expected-no-diagnostics
47

58
// We don't check assumptions at compile time if '-fno-assumptions' is passed,

0 commit comments

Comments
 (0)