-
Notifications
You must be signed in to change notification settings - Fork 0
[PowerPC][AIX] Support #pragma comment copyright for AIX #1
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
base: XCOFFAssociatedMetadata
Are you sure you want to change the base?
Changes from all commits
fbbb701
cfa6019
82254ee
7af5f2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -587,6 +587,10 @@ class CodeGenModule : public CodeGenTypeCache { | |||||
| /// A vector of metadata strings for dependent libraries for ELF. | ||||||
| SmallVector<llvm::MDNode *, 16> ELFDependentLibraries; | ||||||
|
|
||||||
| /// Single module-level copyright comment (if any). | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid "module" without qualification. "Single" is also redundant given the next sentence.
Suggested change
|
||||||
| /// We only ever accept one per TU. | ||||||
| llvm::MDNode *CopyrightCommentInTU = nullptr; | ||||||
|
|
||||||
| /// @name Cache for Objective-C runtime types | ||||||
| /// @{ | ||||||
|
|
||||||
|
|
@@ -1458,6 +1462,8 @@ class CodeGenModule : public CodeGenTypeCache { | |||||
| /// Appends a dependent lib to the appropriate metadata value. | ||||||
| void AddDependentLib(StringRef Lib); | ||||||
|
|
||||||
| /// Process pragma comment | ||||||
| void ProcessPragmaComment(PragmaMSCommentKind Kind, StringRef Comment); | ||||||
|
|
||||||
| llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,6 +236,7 @@ struct PragmaCommentHandler : public PragmaHandler { | |
|
|
||
| private: | ||
| Sema &Actions; | ||
| bool SeenCopyrightInTU = false; // TU-scoped | ||
| }; | ||
|
|
||
| struct PragmaDetectMismatchHandler : public PragmaHandler { | ||
|
|
@@ -473,7 +474,8 @@ void Parser::initializePragmaHandlers() { | |
| PP.AddPragmaHandler(OpenACCHandler.get()); | ||
|
|
||
| if (getLangOpts().MicrosoftExt || | ||
| getTargetInfo().getTriple().isOSBinFormatELF()) { | ||
| getTargetInfo().getTriple().isOSBinFormatELF() || | ||
| getTargetInfo().getTriple().isOSAIX()) { | ||
| MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions); | ||
| PP.AddPragmaHandler(MSCommentHandler.get()); | ||
| } | ||
|
|
@@ -595,7 +597,8 @@ void Parser::resetPragmaHandlers() { | |
| OpenACCHandler.reset(); | ||
|
|
||
| if (getLangOpts().MicrosoftExt || | ||
| getTargetInfo().getTriple().isOSBinFormatELF()) { | ||
| getTargetInfo().getTriple().isOSBinFormatELF() || | ||
| getTargetInfo().getTriple().isOSAIX()) { | ||
| PP.RemovePragmaHandler(MSCommentHandler.get()); | ||
| MSCommentHandler.reset(); | ||
| } | ||
|
|
@@ -3201,13 +3204,26 @@ void PragmaCommentHandler::HandlePragma(Preprocessor &PP, | |
| // Verify that this is one of the 5 explicitly listed options. | ||
| IdentifierInfo *II = Tok.getIdentifierInfo(); | ||
| PragmaMSCommentKind Kind = | ||
| llvm::StringSwitch<PragmaMSCommentKind>(II->getName()) | ||
| .Case("linker", PCK_Linker) | ||
| .Case("lib", PCK_Lib) | ||
| .Case("compiler", PCK_Compiler) | ||
| .Case("exestr", PCK_ExeStr) | ||
| .Case("user", PCK_User) | ||
| .Default(PCK_Unknown); | ||
| llvm::StringSwitch<PragmaMSCommentKind>(II->getName()) | ||
| .Case("linker", PCK_Linker) | ||
| .Case("lib", PCK_Lib) | ||
| .Case("compiler", PCK_Compiler) | ||
| .Case("exestr", PCK_ExeStr) | ||
| .Case("user", PCK_User) | ||
| .Case("copyright", PCK_Copyright) | ||
| .Default(PCK_Unknown); | ||
|
|
||
| // Restrict copyright to AIX targets only | ||
| if (!PP.getTargetInfo().getTriple().isOSAIX()) { | ||
| switch (Kind) { | ||
| case PCK_Copyright: | ||
|
Comment on lines
+3216
to
+3219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This choice of control flow does not stand on its own. To explain the choice, a comment should be added to the code expressing future direction that justifies this structure. For example, we can say that this should be applied for z/OS and extended with other IBM pragma comment kinds. |
||
| Kind = PCK_Unknown; | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (Kind == PCK_Unknown) { | ||
tonykuttai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PP.Diag(Tok.getLocation(), diag::err_pragma_comment_unknown_kind); | ||
| return; | ||
|
|
@@ -3219,6 +3235,16 @@ void PragmaCommentHandler::HandlePragma(Preprocessor &PP, | |
| return; | ||
| } | ||
|
|
||
| // On AIX, pragma comment copyright can each appear only once in a TU. | ||
| if (Kind == PCK_Copyright) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an assert that we are on AIX. The logic has gotten a bit spread out. |
||
| if (SeenCopyrightInTU) { | ||
| PP.Diag(Tok.getLocation(), diag::warn_pragma_comment_once) | ||
| << II->getName(); | ||
| return; | ||
| } | ||
| SeenCopyrightInTU = true; | ||
| } | ||
|
|
||
| // Read the optional string if present. | ||
| PP.Lex(Tok); | ||
| std::string ArgumentString; | ||
|
|
@@ -3245,6 +3271,10 @@ void PragmaCommentHandler::HandlePragma(Preprocessor &PP, | |
| return; | ||
| } | ||
|
|
||
| // Accept and ignore well-formed copyright with empty string. | ||
| if (Kind == PCK_Copyright && ArgumentString.empty()) | ||
| return; | ||
|
|
||
| // If the pragma is lexically sound, notify any interested PPCallbacks. | ||
| if (PP.getPPCallbacks()) | ||
| PP.getPPCallbacks()->PragmaComment(CommentLoc, II, ArgumentString); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // RUN: split-file %s %t | ||
|
|
||
| // Build the module interface to a PCM | ||
| // RUN: %clang_cc1 -std=c++20 -triple powerpc-ibm-aix \ | ||
| // RUN: -emit-module-interface %t/copymod.cppm -o %t/copymod.pcm | ||
|
|
||
| // verify that module interface emit copyright string when compiled to assembly | ||
| // RUN: %clang_cc1 -std=c++20 -triple powerpc-ibm-aix -S %t/copymod.cppm -o - \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-MOD | ||
| // CHECK-MOD: .string "module me" | ||
|
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test can be written to check LLVM IR (to avoid the PowerPC backend requirement). |
||
|
|
||
| // Compile an importing TU that uses the prebuilt module and verify that it | ||
| // does NOT re-emit the module's copyright string. | ||
| // RUN: %clang_cc1 -std=c++20 -triple powerpc-ibm-aix \ | ||
| // RUN: -fprebuilt-module-path=%t -S %t/importmod.cc -o - \ | ||
| // RUN: | FileCheck %s | ||
| // CHECK-NOT: .string "module me" | ||
|
|
||
| //--- copymod.cppm | ||
| export module copymod; | ||
| #pragma comment(copyright, "module me") | ||
| export inline void f() {} | ||
|
|
||
| //--- importmod.cc | ||
| import copymod; | ||
| void g() { f(); } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -triple powerpc64-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -triple powerpc-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -triple powerpc64-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -DTEST_EMPTY_COPYRIGHT -triple powerpc-ibm-aix -verify | ||
|
|
||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc64-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc64-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -x c++ -DTEST_EMPTY_COPYRIGHT -triple powerpc-ibm-aix -verify | ||
|
|
||
| #ifndef TEST_EMPTY_COPYRIGHT | ||
| // Test basic pragma comment types | ||
| #pragma comment(copyright, "@(#) Copyright") | ||
|
|
||
| // Test duplicate copyright - should warn and ignore | ||
| #pragma comment(copyright, "Duplicate Copyright") // expected-warning {{'#pragma comment copyright' can be specified only once per translation unit - ignored}} | ||
|
|
||
| int main() { return 0; } | ||
|
|
||
| // Check that both metadata sections are present | ||
| // CHECK: !loadtime.copyright.comment = !{![[copyright:[0-9]+]]} | ||
|
|
||
| // Check individual metadata content | ||
| // CHECK: ![[copyright]] = !{!"@(#) Copyright"} | ||
|
|
||
| #else | ||
| // Test empty copyright string - valid with no warning | ||
| #pragma comment(copyright, "") // expected-no-diagnostics | ||
|
|
||
| int main() { return 0; } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===-- CopyrightMetadataPass.h - Lower AIX copyright metadata -*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_TRANSFORMS_UTILS_COPYRIGHTMETADATAPASS_H | ||
| #define LLVM_TRANSFORMS_UTILS_COPYRIGHTMETADATAPASS_H | ||
|
|
||
| #include "llvm/IR/PassManager.h" | ||
|
|
||
| namespace llvm { | ||
| class CopyrightMetadataPass : public PassInfoMixin<CopyrightMetadataPass> { | ||
| public: | ||
| PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); | ||
|
|
||
| static bool isRequired() { return true; } | ||
| }; | ||
|
|
||
|
|
||
| } // namespace llvm | ||
|
|
||
| #endif // LLVM_TRANSFORMS_UTILS_COPYRIGHTMETADATAPASS_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider asserting either if this is called not for
copyrightor if it is called forcopyrightbut not for AIX.Silently doing nothing seems questionable (e.g., why was the function called to do nothing in the first place?).