aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenAction.cpp
diff options
context:
space:
mode:
authorJuan Manuel Martinez CaamaƱo <jmartinezcaamao@gmail.com>2025-07-29 08:49:36 +0200
committerGitHub <noreply@github.com>2025-07-29 08:49:36 +0200
commit8b020d5434078145e2fd2b4f1a48bb1c78ace491 (patch)
tree6c9d63e3685f26ec717c5edaac205c65e83aa252 /clang/lib/CodeGen/CodeGenAction.cpp
parent267eb81d5b92294275881f149a9e6bc5b87c0546 (diff)
downloadllvm-8b020d5434078145e2fd2b4f1a48bb1c78ace491.zip
llvm-8b020d5434078145e2fd2b4f1a48bb1c78ace491.tar.gz
llvm-8b020d5434078145e2fd2b4f1a48bb1c78ace491.tar.bz2
[Preprocessor] Do not expand macros if the input is already preprocessed (#137665)
Preprocessing the preprocessor output again interacts poorly with some flag combinations when we perform a separate preprocessing stage. In our case, `-no-integrated-cpp -dD` triggered this issue; but I guess that other flags could also trigger problems (`-save-temps` instead of `-no-integrated-cpp`). Full context (which is quite weird I'll admit): * To cache OpenCL kernel compilation results, we use the `-no-integrated-cpp` for the driver to generate a separate preprocessing command (`clang -E`) before the rest of the compilation. * Some OpenCL C language features are implemented as macro definitions (in `opencl-c-base.h`). The semantic analysis queries the preprocessor to check if these are defined or not, for example, when we checks if a builtin is available when using `-fdeclare-opencl-builtins`. * To preserve these `#define` directives, on the preprocessor's output, we use `-dD`. However, other `#define` directives are also maintained besides OpenCL ones; which triggers the issue shown in this PR. A better fix for our particular case could have been to move the language features implemented as macros into some sort of a flag to be used together with `-fdeclare-opencl-builtins`. But I also thought that not preprocessing preprocessor outputs seemed like something desirable. I hope to work on this on a follow up.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index eb5b604..2c0767f 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -908,6 +908,8 @@ bool CodeGenAction::loadLinkModules(CompilerInstance &CI) {
bool CodeGenAction::hasIRSupport() const { return true; }
void CodeGenAction::EndSourceFileAction() {
+ ASTFrontendAction::EndSourceFileAction();
+
// If the consumer creation failed, do nothing.
if (!getCompilerInstance().hasASTConsumer())
return;
@@ -932,7 +934,7 @@ CodeGenerator *CodeGenAction::getCodeGenerator() const {
bool CodeGenAction::BeginSourceFileAction(CompilerInstance &CI) {
if (CI.getFrontendOpts().GenReducedBMI)
CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
- return true;
+ return ASTFrontendAction::BeginSourceFileAction(CI);
}
static std::unique_ptr<raw_pwrite_stream>