https://github.com/aaronj0 created https://github.com/llvm/llvm-project/pull/218735
Relands #217870 with a fix for the failure in `clang/test/Interpreter/emit-llvm.cpp` seen on ppc64le cc @vgvassilev >From b3244a54a79e09ff1ccbd3d56b1ab45614116f7f Mon Sep 17 00:00:00 2001 From: Aaron Jomy <[email protected]> Date: Sun, 23 Aug 2026 15:51:42 +0200 Subject: [PATCH] Reapply "[clang-repl] Honor -emit-llvm to print incremental IR" --- clang/lib/Interpreter/IncrementalAction.cpp | 1 + clang/lib/Interpreter/Interpreter.cpp | 7 +++++++ clang/test/Interpreter/emit-llvm.cpp | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 clang/test/Interpreter/emit-llvm.cpp diff --git a/clang/lib/Interpreter/IncrementalAction.cpp b/clang/lib/Interpreter/IncrementalAction.cpp index d22031c8fa893..85f00c36dd5aa 100644 --- a/clang/lib/Interpreter/IncrementalAction.cpp +++ b/clang/lib/Interpreter/IncrementalAction.cpp @@ -47,6 +47,7 @@ IncrementalAction::IncrementalAction(CompilerInstance &Instance, case frontend::EmitBC: case frontend::EmitObj: case frontend::PrintPreprocessedInput: + case frontend::EmitLLVM: case frontend::EmitLLVMOnly: Act.reset(new EmitLLVMOnlyAction(&LLVMCtx)); break; diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 0536fdcd548a2..c9b127a360e5d 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -31,6 +31,7 @@ #include "clang/Driver/Tool.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/FrontendTool/Utils.h" @@ -568,6 +569,12 @@ Interpreter::Parse(llvm::StringRef Code) { PartialTranslationUnit &LastPTU = IncrParser->RegisterPTU(*TuOrErr); + // Under -emit-llvm, print the module IR. + if (InitPTUSize && LastPTU.TheModule && + getCompilerInstance()->getFrontendOpts().ProgramAction == + frontend::EmitLLVM) + LastPTU.TheModule->print(llvm::outs(), /*AAW=*/nullptr); + return LastPTU; } diff --git a/clang/test/Interpreter/emit-llvm.cpp b/clang/test/Interpreter/emit-llvm.cpp new file mode 100644 index 0000000000000..39d1dc47c9998 --- /dev/null +++ b/clang/test/Interpreter/emit-llvm.cpp @@ -0,0 +1,21 @@ +// REQUIRES: host-supports-jit +// +// -emit-llvm prints the IR of each input before running them. +// +// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -emit-llvm | FileCheck %s + +extern "C" int add(int a, int b) { return a + b; } +// CHECK: define {{.*}}i32 @add( +// CHECK: ret i32 + +extern "C" int answer = 42; +// CHECK: @answer = {{.*}}i32 42 + +extern "C" int neg(int a) { return -a; } +// CHECK: define {{.*}}i32 @neg( + +extern "C" int r = add(19, 23); +// CHECK: @r = {{.*}}global i32 +// CHECK: call {{.*}}i32 @add( +r +// CHECK: (int) 42 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
