[all-commits] [llvm/llvm-project] 8b020d: [Preprocessor] Do not expand macros if the input i...

Juan Manuel Martinez Caamaño via All-commits all-commits at lists.llvm.org
Mon Jul 28 23:49:57 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8b020d5434078145e2fd2b4f1a48bb1c78ace491
      https://github.com/llvm/llvm-project/commit/8b020d5434078145e2fd2b4f1a48bb1c78ace491
  Author: Juan Manuel Martinez Caamaño <jmartinezcaamao at gmail.com>
  Date:   2025-07-29 (Tue, 29 Jul 2025)

  Changed paths:
    M clang/include/clang/Frontend/FrontendAction.h
    M clang/include/clang/Lex/Preprocessor.h
    M clang/lib/CodeGen/CodeGenAction.cpp
    M clang/lib/Frontend/FrontendActions.cpp
    M clang/lib/Frontend/Rewrite/FrontendActions.cpp
    A clang/test/Preprocessor/preprocess-cpp-output.c
    A clang/test/Preprocessor/preprocess-pragma-cpp-output.c

  Log Message:
  -----------
  [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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list