https://github.com/aaronj0 created https://github.com/llvm/llvm-project/pull/226975
The host path sets the bootstrap module aside with CacheCodeGenModule() once the initial action has run, so the first PTU starts from a fresh module. The CUDA device path skipped this step. The device module that HandleTranslationUnit had already finalized during bootstrap stayed current, and the first device PTU finalized it a second time, resulting in CodeGen adding every module flag twice. The IR verifier then rejects the module. To reproduce, on a build with assertions, or with `-fverify-intermediate-code` (hidden on release builds since the driver disables the verifier there), the first input to `clang-repl --cuda` fails: ``` module flag identifiers must be unique (or of 'require' type) !"nvvm-reflect-ftz" module flag identifiers must be unique (or of 'require' type) !"PIC Level" module flag identifiers must be unique (or of 'require' type) !"frame-pointer" fatal error: error in backend: Broken module found, compilation aborted! ``` Tested on 22.x and main. The `host-supports-cuda` lit probe also hits this: clang/test/Interpreter/CUDA reports UNSUPPORTED instead of failing. After, the first device module carries each flag once and the verifier accepts it. The probe passes and the CUDA tests run on an assertions build. >From 4fdfcf9fa7a293535dc51d682be87258f251e790 Mon Sep 17 00:00:00 2001 From: Aaron Jomy <[email protected]> Date: Thu, 24 Sep 2026 16:00:08 +0200 Subject: [PATCH] [clang-repl] Flush the CUDA device bootstrap module before the first PTU The host path sets the bootstrap module aside with CacheCodeGenModule() once the initial action has run, so the first PTU starts from a fresh module. The CUDA device path skipped this step. The device module that HandleTranslationUnit had already finalized during bootstrap stayed current, and the first device PTU finalized it a second time, resulting in CodeGen adding every module flag twice. The IR verifier then rejects the module. To reproduce, on a build with assertions, or with `-fverify-intermediate-code` (hidden on release builds since the driver disables the verifier there), the first input to `clang-repl --cuda` fails: ``` module flag identifiers must be unique (or of 'require' type) !"nvvm-reflect-ftz" module flag identifiers must be unique (or of 'require' type) !"PIC Level" module flag identifiers must be unique (or of 'require' type) !"frame-pointer" fatal error: error in backend: Broken module found, compilation aborted! ``` Tested on 22.x and main. The `host-supports-cuda` lit probe also hits this: clang/test/Interpreter/CUDA reports UNSUPPORTED instead of failing. After, the first device module carries each flag once and the verifier accepts it. The probe passes and the CUDA tests run on an assertions build. --- clang/lib/Interpreter/Interpreter.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 512b28be5a544e..40fbc83db9107c 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -507,6 +507,9 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI, if (llvm::Error E = ExecuteIncrementalAction(*DCI, *Interp->DeviceAct)) return std::move(E); + // Set the finalized initial device module aside, as the host path does. + Interp->DeviceAct->CacheCodeGenModule(); + Interp->DeviceCI = std::move(DCI); auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>( _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
