Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 10 additions & 8 deletions clang/lib/Basic/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down
7 changes: 1 addition & 6 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

getModule().addModuleFlag(llvm::Module::Error, "zos_product_id",
llvm::MDString::get(VMContext, ProductId));

Expand Down