Skip to content

Commit 2c27013

Browse files
committedDec 20, 2023
[clang] Add getClangVendor() and use it in CodeGenModule.cpp (#75935)
In 9a38a72 `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`. Furthermore, `CLANG_VENDOR` is only passed as a build-time define when compiling `Version.cpp`, so add a `getClangVendor()` function to `Version.h`, and use it in `CodegGenModule.cpp`, instead of relying on the macro. Fixes: 9a38a72
1 parent 5c1a41f commit 2c27013

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed
 

‎clang/include/clang/Basic/Version.h

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ namespace clang {
4040
/// string as getClangRevision.
4141
std::string getLLVMRevision();
4242

43+
/// Retrieves the Clang vendor tag.
44+
std::string getClangVendor();
45+
4346
/// Retrieves the full repository version that is an amalgamation of
4447
/// the information in getClangRepositoryPath() and getClangRevision().
4548
std::string getClangFullRepositoryVersion();

‎clang/lib/Basic/Version.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ std::string getLLVMRevision() {
5757
#endif
5858
}
5959

60+
std::string getClangVendor() {
61+
#ifdef CLANG_VENDOR
62+
return CLANG_VENDOR;
63+
#else
64+
return "";
65+
#endif
66+
}
67+
6068
std::string getClangFullRepositoryVersion() {
6169
std::string buf;
6270
llvm::raw_string_ostream OS(buf);
@@ -92,10 +100,7 @@ std::string getClangFullVersion() {
92100
std::string getClangToolFullVersion(StringRef ToolName) {
93101
std::string buf;
94102
llvm::raw_string_ostream OS(buf);
95-
#ifdef CLANG_VENDOR
96-
OS << CLANG_VENDOR;
97-
#endif
98-
OS << ToolName << " version " CLANG_VERSION_STRING;
103+
OS << getClangVendor() << ToolName << " version " CLANG_VERSION_STRING;
99104

100105
std::string repo = getClangFullRepositoryVersion();
101106
if (!repo.empty()) {
@@ -110,10 +115,7 @@ std::string getClangFullCPPVersion() {
110115
// the one we report on the command line.
111116
std::string buf;
112117
llvm::raw_string_ostream OS(buf);
113-
#ifdef CLANG_VENDOR
114-
OS << CLANG_VENDOR;
115-
#endif
116-
OS << "Clang " CLANG_VERSION_STRING;
118+
OS << getClangVendor() << "Clang " CLANG_VERSION_STRING;
117119

118120
std::string repo = getClangFullRepositoryVersion();
119121
if (!repo.empty()) {

‎clang/lib/CodeGen/CodeGenModule.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -995,12 +995,7 @@ void CodeGenModule::Release() {
995995
uint32_t(CLANG_VERSION_MINOR));
996996
getModule().addModuleFlag(llvm::Module::Warning, "zos_product_patchlevel",
997997
uint32_t(CLANG_VERSION_PATCHLEVEL));
998-
std::string ProductId;
999-
#ifdef CLANG_VENDOR
1000-
ProductId = #CLANG_VENDOR;
1001-
#else
1002-
ProductId = "clang";
1003-
#endif
998+
std::string ProductId = getClangVendor() + "clang";
1004999
getModule().addModuleFlag(llvm::Module::Error, "zos_product_id",
10051000
llvm::MDString::get(VMContext, ProductId));
10061001

0 commit comments

Comments
 (0)