[clang] [clang] Add getClangVendor() and use it in CodeGenModule.cpp (PR #75935)

2023-12-20 Thread Dimitry Andric via cfe-commits

https://github.com/DimitryAndric closed 
https://github.com/llvm/llvm-project/pull/75935
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add getClangVendor() and use it in CodeGenModule.cpp (PR #75935)

2023-12-20 Thread Shoaib Meenai via cfe-commits

https://github.com/smeenai approved this pull request.

LGTM, thanks!

https://github.com/llvm/llvm-project/pull/75935
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add getClangVendor() and use it in CodeGenModule.cpp (PR #75935)

2023-12-20 Thread Dimitry Andric via cfe-commits


@@ -995,12 +995,7 @@ void CodeGenModule::Release() {
   uint32_t(CLANG_VERSION_MINOR));
 getModule().addModuleFlag(llvm::Module::Warning, "zos_product_patchlevel",
   uint32_t(CLANG_VERSION_PATCHLEVEL));
-std::string ProductId;
-#ifdef CLANG_VENDOR
-ProductId = #CLANG_VENDOR;
-#else
-ProductId = "clang";
-#endif
+std::string ProductId = getClangVendor() + "clang";

DimitryAndric wrote:

Note that this is the way you are supposed to get a "product-id-with-vendor", 
as the vendor tag itself normally does not contain the word "clang". For 
example, FreeBSD uses "FreeBSD " (so with a trailing space), and Apple uses 
"Apple " (also with trailing space). If any space is desired between the vendor 
tag and the word "clang", it has to be specified in the vendor tag, and not 
appended here in the string concatenation.

https://github.com/llvm/llvm-project/pull/75935
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add getClangVendor() and use it in CodeGenModule.cpp (PR #75935)

2023-12-20 Thread Dimitry Andric via cfe-commits

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

>From ab5263e77e19ede918faf517dd348018c1982590 Mon Sep 17 00:00:00 2001
From: Dimitry Andric 
Date: Tue, 19 Dec 2023 13:37:37 +0100
Subject: [PATCH] [clang] Add getClangVendor() and use it in CodeGenModule.cpp

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`.

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: 9a38a72f1d482
---
 clang/include/clang/Basic/Version.h |  3 +++
 clang/lib/Basic/Version.cpp | 18 ++
 clang/lib/CodeGen/CodeGenModule.cpp |  7 +--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/Version.h 
b/clang/include/clang/Basic/Version.h
index 2881d8db954e0b..8e4e6928fded50 100644
--- a/clang/include/clang/Basic/Version.h
+++ b/clang/include/clang/Basic/Version.h
@@ -40,6 +40,9 @@ namespace clang {
   /// string as getClangRevision.
   std::string getLLVMRevision();
 
+  /// Retrieves the Clang vendor tag.
+  std::string getClangVendor();
+
   /// Retrieves the full repository version that is an amalgamation of
   /// the information in getClangRepositoryPath() and getClangRevision().
   std::string getClangFullRepositoryVersion();
diff --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp
index e205da7adec1d8..4823f566bd7732 100644
--- a/clang/lib/Basic/Version.cpp
+++ b/clang/lib/Basic/Version.cpp
@@ -57,6 +57,14 @@ std::string getLLVMRevision() {
 #endif
 }
 
+std::string getClangVendor() {
+#ifdef CLANG_VENDOR
+  return CLANG_VENDOR;
+#else
+  return "";
+#endif
+}
+
 std::string getClangFullRepositoryVersion() {
   std::string buf;
   llvm::raw_string_ostream OS(buf);
@@ -92,10 +100,7 @@ std::string getClangFullVersion() {
 std::string getClangToolFullVersion(StringRef ToolName) {
   std::string buf;
   llvm::raw_string_ostream OS(buf);
-#ifdef CLANG_VENDOR
-  OS << CLANG_VENDOR;
-#endif
-  OS << ToolName << " version " CLANG_VERSION_STRING;
+  OS << getClangVendor() << ToolName << " version " CLANG_VERSION_STRING;
 
   std::string repo = getClangFullRepositoryVersion();
   if (!repo.empty()) {
@@ -110,10 +115,7 @@ std::string getClangFullCPPVersion() {
   // the one we report on the command line.
   std::string buf;
   llvm::raw_string_ostream OS(buf);
-#ifdef CLANG_VENDOR
-  OS << CLANG_VENDOR;
-#endif
-  OS << "Clang " CLANG_VERSION_STRING;
+  OS << getClangVendor() << "Clang " CLANG_VERSION_STRING;
 
   std::string repo = getClangFullRepositoryVersion();
   if (!repo.empty()) {
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 7ad26ace328ab2..b2e173d0d6949e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -995,12 +995,7 @@ void CodeGenModule::Release() {
   uint32_t(CLANG_VERSION_MINOR));
 getModule().addModuleFlag(llvm::Module::Warning, "zos_product_patchlevel",
   uint32_t(CLANG_VERSION_PATCHLEVEL));
-std::string ProductId;
-#ifdef CLANG_VENDOR
-ProductId = #CLANG_VENDOR;
-#else
-ProductId = "clang";
-#endif
+std::string ProductId = getClangVendor() + "clang";
 getModule().addModuleFlag(llvm::Module::Error, "zos_product_id",
   llvm::MDString::get(VMContext, ProductId));
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add getClangVendor() and use it in CodeGenModule.cpp (PR #75935)

2023-12-20 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff b01adc6bed7e5b924dd8a097be0aa893f4823905 
4b3db6bdaf9f94277f23bf9a796f474a353e4d73 -- clang/include/clang/Basic/Version.h 
clang/lib/Basic/Version.cpp clang/lib/CodeGen/CodeGenModule.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp
index 67aa653770..4823f566bd 100644
--- a/clang/lib/Basic/Version.cpp
+++ b/clang/lib/Basic/Version.cpp
@@ -57,8 +57,7 @@ std::string getLLVMRevision() {
 #endif
 }
 
-std::string getClangVendor()
-{
+std::string getClangVendor() {
 #ifdef CLANG_VENDOR
   return CLANG_VENDOR;
 #else

``




https://github.com/llvm/llvm-project/pull/75935
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add getClangVendor() and use it in CodeGenModule.cpp (PR #75935)

2023-12-20 Thread Dimitry Andric via cfe-commits

https://github.com/DimitryAndric edited 
https://github.com/llvm/llvm-project/pull/75935
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits