[clang] [clang][CodeGen] Always use CLANG_VENDOR as a quoted string (PR #75935)

Dimitry Andric via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 19 06:16:23 PST 2023


https://github.com/DimitryAndric created https://github.com/llvm/llvm-project/pull/75935

In 9a38a72f1d482 `ProductId` was assigned from the stringified value of `CLANG_VENDOR`, if that macro was defined. However, `CLANG_VENDOR` is supposed to be a string, as it is defined (optionally) as such in the top-level clang `CMakeLists.txt`.

Move the addition of `-DCLANG_VENDOR` to the compiler flags from `clang/lib/Basic/CMakeLists.txt` to the top-level `CMakeLists.txt`, so it is consistent across the whole clang codebase. Then remove the stringification from `CodeGenModule.cpp`, to make it work correctly.

Fixes:		9a38a72f1d482

>From ce2f3105a5270a26fa3595313289dcbfa700abb9 Mon Sep 17 00:00:00 2001
From: Dimitry Andric <dimitry at andric.com>
Date: Tue, 19 Dec 2023 13:37:37 +0100
Subject: [PATCH] [clang][CodeGen] Always use CLANG_VENDOR as a quoted string

In 9a38a72f1d482 `ProductId` was assigned from the stringified value of
`CLANG_VENDOR`, if that macro was defined. However, `CLANG_VENDOR` is
supposed to be a string, as it is defined (optionally) as such in the
top-level clang `CMakeLists.txt`.

Move the addition of `-DCLANG_VENDOR` to the compiler flags from
`clang/lib/Basic/CMakeLists.txt` to the top-level `CMakeLists.txt`, so
it is consistent across the whole clang codebase. Then remove the
stringification from `CodeGenModule.cpp`, to make it work correctly.

Fixes:		9a38a72f1d482
---
 clang/CMakeLists.txt                | 4 ++++
 clang/lib/Basic/CMakeLists.txt      | 5 -----
 clang/lib/CodeGen/CodeGenModule.cpp | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 2ca6db02e58791..c7461bc510e4ac 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -241,6 +241,10 @@ set(CLANG_SYSTEMZ_DEFAULT_ARCH "z10" CACHE STRING "SystemZ Default Arch")
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")
 
+if(CLANG_VENDOR)
+  add_definitions(-DCLANG_VENDOR="${CLANG_VENDOR}")
+endif()
+
 set(CLANG_REPOSITORY_STRING "" CACHE STRING
   "Vendor-specific text for showing the repository the source is taken from.")
 
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 2e218ba7c84cca..6b6fde9b5a9a6b 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -49,11 +49,6 @@ set_source_files_properties("${version_inc}"
   PROPERTIES GENERATED TRUE
              HEADER_FILE_ONLY TRUE)
 
-if(CLANG_VENDOR)
-  set_source_files_properties(Version.cpp
-    PROPERTIES COMPILE_DEFINITIONS "CLANG_VENDOR=\"${CLANG_VENDOR} \"")
-endif()
-
 add_clang_library(clangBasic
   Attributes.cpp
   Builtins.cpp
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 7ad26ace328ab2..c8007aef675cb4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -997,7 +997,7 @@ void CodeGenModule::Release() {
                               uint32_t(CLANG_VERSION_PATCHLEVEL));
     std::string ProductId;
 #ifdef CLANG_VENDOR
-    ProductId = #CLANG_VENDOR;
+    ProductId = CLANG_VENDOR;
 #else
     ProductId = "clang";
 #endif



More information about the cfe-commits mailing list