[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi added a comment. Eli, if you have trouble committing this please let me know. Not sure what is happening. https://reviews.llvm.org/D37861 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi created this revision. Herald added subscribers: kbarton, nemanjai. When #pragma clang assume_nonnull begin || end is present in the source it is completely gone from pre-processed output when compiled with -E or -P. This patch make sure the pragma is preserved. I included 1 test case which checks the presence of this pragma in pre-processor output. https://reviews.llvm.org/D37861 Files: include/clang/Lex/PPCallbacks.h lib/Frontend/PrintPreprocessedOutput.cpp lib/Lex/Pragma.cpp test/Preprocessor/pragma_assume_nonnull.c Index: test/Preprocessor/pragma_assume_nonnull.c === --- /dev/null +++ test/Preprocessor/pragma_assume_nonnull.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -E %s | FileCheck %s + +#ifndef NS_ASSUME_NONNULL_BEGIN +#if __has_feature(assume_nonnull) +#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") +#define NS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") +#else +#define NS_ASSUME_NONNULL_BEGIN +#define NS_ASSUME_NONNULL_END +#endif +#endif + +// CHECK: #pragma clang assume_nonnull begin +NS_ASSUME_NONNULL_BEGIN + +int bar(int * ip) { return *ip; } + +// CHECK: #pragma clang assume_nonnull end +NS_ASSUME_NONNULL_END + +int foo(int * _Nonnull ip) { return *ip; } + +int main() { +#if __has_feature(assume_nonnull) + return bar(0) + foo(0); // expected-warning 2 {{null passed to a callee that requires a non-null argument}} +#else + return bar(0) + foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}} +#endif +} + Index: lib/Lex/Pragma.cpp === --- lib/Lex/Pragma.cpp +++ lib/Lex/Pragma.cpp @@ -1725,21 +1725,26 @@ // The start location we want after processing this. SourceLocation NewLoc; +PPCallbacks *Callbacks = PP.getPPCallbacks(); if (IsBegin) { // Complain about attempts to re-enter an audit. if (BeginLoc.isValid()) { PP.Diag(Loc, diag::err_pp_double_begin_of_assume_nonnull); PP.Diag(BeginLoc, diag::note_pragma_entered_here); } NewLoc = Loc; + if (Callbacks) +Callbacks->PragmaAssumeNonNullBegin(NewLoc); } else { // Complain about attempts to leave an audit that doesn't exist. if (!BeginLoc.isValid()) { PP.Diag(Loc, diag::err_pp_unmatched_end_of_assume_nonnull); return; } NewLoc = SourceLocation(); + if (Callbacks) +Callbacks->PragmaAssumeNonNullEnd(NewLoc); } PP.setPragmaAssumeNonNullLoc(NewLoc); Index: lib/Frontend/PrintPreprocessedOutput.cpp === --- lib/Frontend/PrintPreprocessedOutput.cpp +++ lib/Frontend/PrintPreprocessedOutput.cpp @@ -143,6 +143,8 @@ ArrayRef Ids) override; void PragmaWarningPush(SourceLocation Loc, int Level) override; void PragmaWarningPop(SourceLocation Loc) override; + void PragmaAssumeNonNullBegin(SourceLocation Loc) override; + void PragmaAssumeNonNullEnd(SourceLocation Loc) override; bool HandleFirstTokOnLine(Token &Tok); @@ -549,6 +551,22 @@ setEmittedDirectiveOnThisLine(); } +void PrintPPOutputPPCallbacks:: +PragmaAssumeNonNullBegin(SourceLocation Loc) { + startNewLineIfNeeded(); + MoveToLine(Loc); + OS << "#pragma " << "clang assume_nonnull begin"; + setEmittedDirectiveOnThisLine(); +} + +void PrintPPOutputPPCallbacks:: +PragmaAssumeNonNullEnd(SourceLocation Loc) { + startNewLineIfNeeded(); + MoveToLine(Loc); + OS << "#pragma " << "clang assume_nonnull end"; + setEmittedDirectiveOnThisLine(); +} + /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this /// is called for the first token on each new line. If this really is the start /// of a new logical line, handle it and return true, otherwise return false. Index: include/clang/Lex/PPCallbacks.h === --- include/clang/Lex/PPCallbacks.h +++ include/clang/Lex/PPCallbacks.h @@ -235,6 +235,14 @@ virtual void PragmaWarningPop(SourceLocation Loc) { } + /// \brief Callback invoked when a \#pragma clang assume_nonnull begin directive + /// is read. + virtual void PragmaAssumeNonNullBegin(SourceLocation Loc) {} + + /// \brief Callback invoked when a \#pragma clang assume_nonnull end directive + /// is read. + virtual void PragmaAssumeNonNullEnd(SourceLocation Loc) {} + /// \brief Called by Preprocessor::HandleMacroExpandedIdentifier when a /// macro invocation is found. virtual void MacroExpands(const Token &MacroNameTok, @@ -443,6 +451,16 @@ Second->PragmaWarningPop(Loc); } + void PragmaAssumeNonNullBegin(SourceLocation Loc) override { +First->PragmaAssumeNonNullBegin(Loc); +Second->PragmaAssumeNonNullBegin(Loc); + } + + void PragmaAssumeNonNullEnd(SourceLocation Loc) ove
[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi updated this revision to Diff 115643. zibi added a comment. Addressing the review. https://reviews.llvm.org/D37861 Files: lib/Frontend/PrintPreprocessedOutput.cpp test/Preprocessor/pragma_assume_nonnull.c Index: test/Preprocessor/pragma_assume_nonnull.c === --- test/Preprocessor/pragma_assume_nonnull.c +++ test/Preprocessor/pragma_assume_nonnull.c @@ -1,23 +1,13 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -E %s | FileCheck %s -#ifndef NS_ASSUME_NONNULL_BEGIN -#if __has_feature(assume_nonnull) -#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") -#define NS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") -#else -#define NS_ASSUME_NONNULL_BEGIN -#define NS_ASSUME_NONNULL_END -#endif -#endif - // CHECK: #pragma clang assume_nonnull begin -NS_ASSUME_NONNULL_BEGIN +#pragma clang assume_nonnull begin int bar(int * ip) { return *ip; } // CHECK: #pragma clang assume_nonnull end -NS_ASSUME_NONNULL_END +#pragma clang assume_nonnull end int foo(int * _Nonnull ip) { return *ip; } @@ -28,4 +18,3 @@ return bar(0) + foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}} #endif } - Index: lib/Frontend/PrintPreprocessedOutput.cpp === --- lib/Frontend/PrintPreprocessedOutput.cpp +++ lib/Frontend/PrintPreprocessedOutput.cpp @@ -555,15 +555,15 @@ PragmaAssumeNonNullBegin(SourceLocation Loc) { startNewLineIfNeeded(); MoveToLine(Loc); - OS << "#pragma " << "clang assume_nonnull begin"; + OS << "#pragma clang assume_nonnull begin"; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks:: PragmaAssumeNonNullEnd(SourceLocation Loc) { startNewLineIfNeeded(); MoveToLine(Loc); - OS << "#pragma " << "clang assume_nonnull end"; + OS << "#pragma clang assume_nonnull end"; setEmittedDirectiveOnThisLine(); } Index: test/Preprocessor/pragma_assume_nonnull.c === --- test/Preprocessor/pragma_assume_nonnull.c +++ test/Preprocessor/pragma_assume_nonnull.c @@ -1,23 +1,13 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -E %s | FileCheck %s -#ifndef NS_ASSUME_NONNULL_BEGIN -#if __has_feature(assume_nonnull) -#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") -#define NS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") -#else -#define NS_ASSUME_NONNULL_BEGIN -#define NS_ASSUME_NONNULL_END -#endif -#endif - // CHECK: #pragma clang assume_nonnull begin -NS_ASSUME_NONNULL_BEGIN +#pragma clang assume_nonnull begin int bar(int * ip) { return *ip; } // CHECK: #pragma clang assume_nonnull end -NS_ASSUME_NONNULL_END +#pragma clang assume_nonnull end int foo(int * _Nonnull ip) { return *ip; } @@ -28,4 +18,3 @@ return bar(0) + foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}} #endif } - Index: lib/Frontend/PrintPreprocessedOutput.cpp === --- lib/Frontend/PrintPreprocessedOutput.cpp +++ lib/Frontend/PrintPreprocessedOutput.cpp @@ -555,15 +555,15 @@ PragmaAssumeNonNullBegin(SourceLocation Loc) { startNewLineIfNeeded(); MoveToLine(Loc); - OS << "#pragma " << "clang assume_nonnull begin"; + OS << "#pragma clang assume_nonnull begin"; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks:: PragmaAssumeNonNullEnd(SourceLocation Loc) { startNewLineIfNeeded(); MoveToLine(Loc); - OS << "#pragma " << "clang assume_nonnull end"; + OS << "#pragma clang assume_nonnull end"; setEmittedDirectiveOnThisLine(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi marked 2 inline comments as done. zibi added a comment. Good catch, thank you. I submitted a new patch. https://reviews.llvm.org/D37861 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi updated this revision to Diff 115838. zibi added a comment. original + review changes https://reviews.llvm.org/D37861 Files: include/clang/Lex/PPCallbacks.h lib/Frontend/PrintPreprocessedOutput.cpp lib/Lex/Pragma.cpp test/Preprocessor/pragma_assume_nonnull.c Index: test/Preprocessor/pragma_assume_nonnull.c === --- /dev/null +++ test/Preprocessor/pragma_assume_nonnull.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -E %s | FileCheck %s + +// CHECK: #pragma clang assume_nonnull begin +#pragma clang assume_nonnull begin + +int bar(int * ip) { return *ip; } + +// CHECK: #pragma clang assume_nonnull end +#pragma clang assume_nonnull end + +int foo(int * _Nonnull ip) { return *ip; } + +int main() { +#if __has_feature(assume_nonnull) + return bar(0) + foo(0); // expected-warning 2 {{null passed to a callee that requires a non-null argument}} +#else + return bar(0) + foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}} +#endif +} Index: lib/Lex/Pragma.cpp === --- lib/Lex/Pragma.cpp +++ lib/Lex/Pragma.cpp @@ -1725,21 +1725,26 @@ // The start location we want after processing this. SourceLocation NewLoc; +PPCallbacks *Callbacks = PP.getPPCallbacks(); if (IsBegin) { // Complain about attempts to re-enter an audit. if (BeginLoc.isValid()) { PP.Diag(Loc, diag::err_pp_double_begin_of_assume_nonnull); PP.Diag(BeginLoc, diag::note_pragma_entered_here); } NewLoc = Loc; + if (Callbacks) +Callbacks->PragmaAssumeNonNullBegin(NewLoc); } else { // Complain about attempts to leave an audit that doesn't exist. if (!BeginLoc.isValid()) { PP.Diag(Loc, diag::err_pp_unmatched_end_of_assume_nonnull); return; } NewLoc = SourceLocation(); + if (Callbacks) +Callbacks->PragmaAssumeNonNullEnd(NewLoc); } PP.setPragmaAssumeNonNullLoc(NewLoc); Index: lib/Frontend/PrintPreprocessedOutput.cpp === --- lib/Frontend/PrintPreprocessedOutput.cpp +++ lib/Frontend/PrintPreprocessedOutput.cpp @@ -143,6 +143,8 @@ ArrayRef Ids) override; void PragmaWarningPush(SourceLocation Loc, int Level) override; void PragmaWarningPop(SourceLocation Loc) override; + void PragmaAssumeNonNullBegin(SourceLocation Loc) override; + void PragmaAssumeNonNullEnd(SourceLocation Loc) override; bool HandleFirstTokOnLine(Token &Tok); @@ -549,6 +551,22 @@ setEmittedDirectiveOnThisLine(); } +void PrintPPOutputPPCallbacks:: +PragmaAssumeNonNullBegin(SourceLocation Loc) { + startNewLineIfNeeded(); + MoveToLine(Loc); + OS << "#pragma clang assume_nonnull begin"; + setEmittedDirectiveOnThisLine(); +} + +void PrintPPOutputPPCallbacks:: +PragmaAssumeNonNullEnd(SourceLocation Loc) { + startNewLineIfNeeded(); + MoveToLine(Loc); + OS << "#pragma clang assume_nonnull end"; + setEmittedDirectiveOnThisLine(); +} + /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this /// is called for the first token on each new line. If this really is the start /// of a new logical line, handle it and return true, otherwise return false. Index: include/clang/Lex/PPCallbacks.h === --- include/clang/Lex/PPCallbacks.h +++ include/clang/Lex/PPCallbacks.h @@ -235,6 +235,14 @@ virtual void PragmaWarningPop(SourceLocation Loc) { } + /// \brief Callback invoked when a \#pragma clang assume_nonnull begin directive + /// is read. + virtual void PragmaAssumeNonNullBegin(SourceLocation Loc) {} + + /// \brief Callback invoked when a \#pragma clang assume_nonnull end directive + /// is read. + virtual void PragmaAssumeNonNullEnd(SourceLocation Loc) {} + /// \brief Called by Preprocessor::HandleMacroExpandedIdentifier when a /// macro invocation is found. virtual void MacroExpands(const Token &MacroNameTok, @@ -443,6 +451,16 @@ Second->PragmaWarningPop(Loc); } + void PragmaAssumeNonNullBegin(SourceLocation Loc) override { +First->PragmaAssumeNonNullBegin(Loc); +Second->PragmaAssumeNonNullBegin(Loc); + } + + void PragmaAssumeNonNullEnd(SourceLocation Loc) override { +First->PragmaAssumeNonNullEnd(Loc); +Second->PragmaAssumeNonNullEnd(Loc); + } + void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override { First->MacroExpands(MacroNameTok, MD, Range, Args); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi added a comment. Please be aware that I don't have the commit permission yet since this is my first patch. I will rely on somebody to push it to the trunk. https://reviews.llvm.org/D37861 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi added a comment. ping https://reviews.llvm.org/D37861 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output
zibi added a comment. Yes, please do the commit, thank you. In https://reviews.llvm.org/D37861#878194, @efriedma wrote: > LGTM. > > Do you want me to commit this for you? https://reviews.llvm.org/D37861 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D91565: Guard init_priority attribute within libc++
zibi updated this revision to Diff 306162. zibi marked an inline comment as done. zibi added a comment. Herald added a reviewer: aaron.ballman. Herald added a project: clang. Herald added a subscriber: cfe-commits. I moved the logic from `memory_resource.cpp` to `__config` as since I'm not familiar with Apple and Microsoft restrictions are still correct. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91565/new/ https://reviews.llvm.org/D91565 Files: clang/include/clang/Basic/Attr.td libcxx/include/__config libcxx/include/experimental/__config libcxx/src/experimental/memory_resource.cpp libcxx/src/iostream.cpp Index: libcxx/src/iostream.cpp === --- libcxx/src/iostream.cpp +++ libcxx/src/iostream.cpp @@ -77,7 +77,7 @@ #endif ; -_LIBCPP_HIDDEN ios_base::Init __start_std_streams __attribute__((init_priority(101))); +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination Index: libcxx/src/experimental/memory_resource.cpp === --- libcxx/src/experimental/memory_resource.cpp +++ libcxx/src/experimental/memory_resource.cpp @@ -76,16 +76,6 @@ ~ResourceInitHelper() {} }; -// Detect if the init_priority attribute is supported. -#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ - || defined(_LIBCPP_COMPILER_MSVC) -// GCC on Apple doesn't support the init priority attribute, -// and MSVC doesn't support any GCC attributes. -# define _LIBCPP_INIT_PRIORITY_MAX -#else -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) -#endif - // When compiled in C++14 this initialization should be a constant expression. // Only in C++11 is "init_priority" needed to ensure initialization order. #if _LIBCPP_STD_VER > 11 Index: libcxx/include/experimental/__config === --- libcxx/include/experimental/__config +++ libcxx/include/experimental/__config @@ -76,4 +76,14 @@ #define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 16 #endif +// Detect if the init_priority attribute is supported. +#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ + || defined(_LIBCPP_COMPILER_MSVC) || defined(__MVS__) +// GCC on Apple doesn't support the init priority +// attribute, same for MSVC and z/OS. +# define _LIBCPP_INIT_PRIORITY_MAX +#else +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +#endif + #endif Index: libcxx/include/__config === --- libcxx/include/__config +++ libcxx/include/__config @@ -1435,6 +1435,12 @@ #define _LIBCPP_HAS_NO_FGETPOS_FSETPOS #endif +#if __has_attribute(init_priority) +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +#else +# define _LIBCPP_INIT_PRIORITY_MAX +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG Index: clang/include/clang/Basic/Attr.td === --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -381,6 +381,9 @@ let ObjectFormats = ["ELF"]; } +def ExcludeTarget : TargetSpec { + let CustomCode = [{ !Target.getTriple().isOSzOS() }]; +} // Attribute subject match rules that are used for #pragma clang attribute. // // A instance of AttrSubjectMatcherRule represents an individual match rule. @@ -2221,7 +2224,7 @@ let Documentation = [Undocumented]; } -def InitPriority : InheritableAttr { +def InitPriority : InheritableAttr, TargetSpecificAttr { let Spellings = [GCC<"init_priority", /*AllowInC*/0>]; let Args = [UnsignedArgument<"Priority">]; let Subjects = SubjectList<[Var], ErrorDiag>; Index: libcxx/src/iostream.cpp === --- libcxx/src/iostream.cpp +++ libcxx/src/iostream.cpp @@ -77,7 +77,7 @@ #endif ; -_LIBCPP_HIDDEN ios_base::Init __start_std_streams __attribute__((init_priority(101))); +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination Index: libcxx/src/experimental/memory_resource.cpp === --- libcxx/src/experimental/memory_resource.cpp +++ libcxx/src/experimental/memory_resource.cpp @@ -76,16 +76,6 @@ ~ResourceInitHelper() {} }; -// Detect if the init_priority attribute is supported. -#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ - || defined(_LIBCPP_COMPILER_MSVC) -// GCC on Apple doesn't support the init priority attribute, -// and MSVC doesn't support a
[PATCH] D91565: Guard init_priority attribute within libc++
zibi updated this revision to Diff 306183. zibi marked an inline comment as done. zibi added a comment. Moving macro to common place as requested. This makes assumption that MS and Apple restrictions were lifted at some point. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91565/new/ https://reviews.llvm.org/D91565 Files: clang/include/clang/Basic/Attr.td libcxx/include/__config libcxx/src/experimental/memory_resource.cpp libcxx/src/iostream.cpp Index: libcxx/src/iostream.cpp === --- libcxx/src/iostream.cpp +++ libcxx/src/iostream.cpp @@ -77,7 +77,7 @@ #endif ; -_LIBCPP_HIDDEN ios_base::Init __start_std_streams __attribute__((init_priority(101))); +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination Index: libcxx/src/experimental/memory_resource.cpp === --- libcxx/src/experimental/memory_resource.cpp +++ libcxx/src/experimental/memory_resource.cpp @@ -76,16 +76,6 @@ ~ResourceInitHelper() {} }; -// Detect if the init_priority attribute is supported. -#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ - || defined(_LIBCPP_COMPILER_MSVC) -// GCC on Apple doesn't support the init priority attribute, -// and MSVC doesn't support any GCC attributes. -# define _LIBCPP_INIT_PRIORITY_MAX -#else -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) -#endif - // When compiled in C++14 this initialization should be a constant expression. // Only in C++11 is "init_priority" needed to ensure initialization order. #if _LIBCPP_STD_VER > 11 Index: libcxx/include/__config === --- libcxx/include/__config +++ libcxx/include/__config @@ -1435,6 +1435,12 @@ #define _LIBCPP_HAS_NO_FGETPOS_FSETPOS #endif +#if __has_attribute(init_priority) +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +#else +# define _LIBCPP_INIT_PRIORITY_MAX +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG Index: clang/include/clang/Basic/Attr.td === --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -381,6 +381,9 @@ let ObjectFormats = ["ELF"]; } +def ExcludeTarget : TargetSpec { + let CustomCode = [{ !Target.getTriple().isOSzOS() }]; +} // Attribute subject match rules that are used for #pragma clang attribute. // // A instance of AttrSubjectMatcherRule represents an individual match rule. @@ -2221,7 +2224,7 @@ let Documentation = [Undocumented]; } -def InitPriority : InheritableAttr { +def InitPriority : InheritableAttr, TargetSpecificAttr { let Spellings = [GCC<"init_priority", /*AllowInC*/0>]; let Args = [UnsignedArgument<"Priority">]; let Subjects = SubjectList<[Var], ErrorDiag>; Index: libcxx/src/iostream.cpp === --- libcxx/src/iostream.cpp +++ libcxx/src/iostream.cpp @@ -77,7 +77,7 @@ #endif ; -_LIBCPP_HIDDEN ios_base::Init __start_std_streams __attribute__((init_priority(101))); +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination Index: libcxx/src/experimental/memory_resource.cpp === --- libcxx/src/experimental/memory_resource.cpp +++ libcxx/src/experimental/memory_resource.cpp @@ -76,16 +76,6 @@ ~ResourceInitHelper() {} }; -// Detect if the init_priority attribute is supported. -#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ - || defined(_LIBCPP_COMPILER_MSVC) -// GCC on Apple doesn't support the init priority attribute, -// and MSVC doesn't support any GCC attributes. -# define _LIBCPP_INIT_PRIORITY_MAX -#else -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) -#endif - // When compiled in C++14 this initialization should be a constant expression. // Only in C++11 is "init_priority" needed to ensure initialization order. #if _LIBCPP_STD_VER > 11 Index: libcxx/include/__config === --- libcxx/include/__config +++ libcxx/include/__config @@ -1435,6 +1435,12 @@ #define _LIBCPP_HAS_NO_FGETPOS_FSETPOS #endif +#if __has_attribute(init_priority) +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +#else +# define _LIBCPP_INIT_PRIORITY_MAX +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG Index: clang/include/clang/Basic/Attr.td =
[PATCH] D91565: Guard init_priority attribute within libc++
zibi marked an inline comment as done. zibi added inline comments. Comment at: clang/include/clang/Basic/Attr.td:384 +def ExcludeTarget : TargetSpec { + let CustomCode = [{ !Target.getTriple().isOSzOS() }]; aaron.ballman wrote: > This is not a very descriptive name -- if this is only supposed to be used > for `init_priority` how about `TargetSupportsInitPriority` instead? > > Also, this change is missing test coverage and documentation changes. For now, we can use `TargetSupportsInitPriority`, we can always change it if we find the need to disable other attributes. Thank you Arraon for review and suggestion for the name. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91565/new/ https://reviews.llvm.org/D91565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D91565: Guard init_priority attribute within libc++
zibi updated this revision to Diff 306524. zibi marked an inline comment as done. zibi added a comment. updated doc. and test as requested Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91565/new/ https://reviews.llvm.org/D91565 Files: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/test/SemaCXX/init-priority-attr.cpp libcxx/include/__config libcxx/src/experimental/memory_resource.cpp libcxx/src/iostream.cpp Index: libcxx/src/iostream.cpp === --- libcxx/src/iostream.cpp +++ libcxx/src/iostream.cpp @@ -77,7 +77,7 @@ #endif ; -_LIBCPP_HIDDEN ios_base::Init __start_std_streams __attribute__((init_priority(101))); +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination Index: libcxx/src/experimental/memory_resource.cpp === --- libcxx/src/experimental/memory_resource.cpp +++ libcxx/src/experimental/memory_resource.cpp @@ -76,16 +76,6 @@ ~ResourceInitHelper() {} }; -// Detect if the init_priority attribute is supported. -#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ - || defined(_LIBCPP_COMPILER_MSVC) -// GCC on Apple doesn't support the init priority attribute, -// and MSVC doesn't support any GCC attributes. -# define _LIBCPP_INIT_PRIORITY_MAX -#else -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) -#endif - // When compiled in C++14 this initialization should be a constant expression. // Only in C++11 is "init_priority" needed to ensure initialization order. #if _LIBCPP_STD_VER > 11 Index: libcxx/include/__config === --- libcxx/include/__config +++ libcxx/include/__config @@ -1435,6 +1435,12 @@ #define _LIBCPP_HAS_NO_FGETPOS_FSETPOS #endif +#if __has_attribute(init_priority) +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +#else +# define _LIBCPP_INIT_PRIORITY_MAX +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG Index: clang/test/SemaCXX/init-priority-attr.cpp === --- clang/test/SemaCXX/init-priority-attr.cpp +++ clang/test/SemaCXX/init-priority-attr.cpp @@ -23,25 +23,67 @@ extern Two koo[]; Two foo __attribute__((init_priority(101))) ( 5, 6 ); +#if defined(__MVS__) + #if defined(SYSTEM) + // expected-no-diagnostics + #else + // expected-warning@-5 {{unknown attribute 'init_priority' ignored}} + #endif +#endif -Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // expected-error {{'init_priority' attribute takes one argument}} +Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); +#if !defined(__MVS__) +// expected-error@-2 {{'init_priority' attribute takes one argument}} +#elif !defined(SYSTEM) +// expected-warning@-4 {{unknown attribute 'init_priority' ignored}} +#endif Two coo[2] __attribute__((init_priority(100))); #if !defined(SYSTEM) -// expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + #if !defined(__MVS__) + // expected-error@-3 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + #else + // expected-warning@-5 {{unknown attribute 'init_priority' ignored}} + #endif #endif Two boo[2] __attribute__((init_priority(65536))); #if !defined(SYSTEM) -// expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + #if !defined(__MVS__) + // expected-error@-3 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + #else + // expected-warning@-5 {{unknown attribute 'init_priority' ignored}} + #endif +#endif + +Two koo[4] __attribute__((init_priority(1.13))); +#if !defined(__MVS__) +// expected-error@-2 {{'init_priority' attribute requires an integer constant}} +#elif !defined(SYSTEM) +// expected-warning@-4 {{unknown attribute 'init_priority' ignored}} #endif -Two koo[4] __attribute__((init_priority(1.13))); // expected-error {{'init_priority' attribute requires an integer constant}} +Two func() __attribute__((init_priority(1001))); +#if !defined(__MVS__) +// expected-error@-2 {{'init_priority' attribute only applies to variables}} +#elif !defined(SYSTEM) +// expected-warning@-4 {{unknown attribute 'init_priority' ignored}} +#endif -Two func() __attribute__((init_priority(1001))); // expected-error {{'init_priority' attribute only applies to variables}} -int i __attribute__((init_priority(1001))); // expected-error {{can only use 'init_priority' attribute on file-scope definitions of objects of class type}} +int i __attribute__((init_priority(1001))); +#if !defined(__MVS__) +// exp
[PATCH] D91565: Guard init_priority attribute within libc++
zibi updated this revision to Diff 306753. zibi added a comment. Make test cleaner. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91565/new/ https://reviews.llvm.org/D91565 Files: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/test/SemaCXX/init-priority-attr.cpp libcxx/include/__config libcxx/src/experimental/memory_resource.cpp libcxx/src/iostream.cpp Index: libcxx/src/iostream.cpp === --- libcxx/src/iostream.cpp +++ libcxx/src/iostream.cpp @@ -77,7 +77,7 @@ #endif ; -_LIBCPP_HIDDEN ios_base::Init __start_std_streams __attribute__((init_priority(101))); +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination Index: libcxx/src/experimental/memory_resource.cpp === --- libcxx/src/experimental/memory_resource.cpp +++ libcxx/src/experimental/memory_resource.cpp @@ -76,16 +76,6 @@ ~ResourceInitHelper() {} }; -// Detect if the init_priority attribute is supported. -#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ - || defined(_LIBCPP_COMPILER_MSVC) -// GCC on Apple doesn't support the init priority attribute, -// and MSVC doesn't support any GCC attributes. -# define _LIBCPP_INIT_PRIORITY_MAX -#else -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) -#endif - // When compiled in C++14 this initialization should be a constant expression. // Only in C++11 is "init_priority" needed to ensure initialization order. #if _LIBCPP_STD_VER > 11 Index: libcxx/include/__config === --- libcxx/include/__config +++ libcxx/include/__config @@ -1435,6 +1435,12 @@ #define _LIBCPP_HAS_NO_FGETPOS_FSETPOS #endif +#if __has_attribute(init_priority) +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +#else +# define _LIBCPP_INIT_PRIORITY_MAX +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG Index: clang/test/SemaCXX/init-priority-attr.cpp === --- clang/test/SemaCXX/init-priority-attr.cpp +++ clang/test/SemaCXX/init-priority-attr.cpp @@ -1,5 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -// RUN: %clang_cc1 -fsyntax-only -DSYSTEM -verify %s +// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -fsyntax-only -DSYSTEM -verify %s +// RUN: %clang_cc1 -triple=s390x-none-zos -fsyntax-only -verify=unknown %s +// RUN: %clang_cc1 -triple=s390x-none-zos -fsyntax-only -DSYSTEM -verify=unknown-system %s #if defined(SYSTEM) #5 "init-priority-attr.cpp" 3 // system header @@ -23,25 +25,35 @@ extern Two koo[]; Two foo __attribute__((init_priority(101))) ( 5, 6 ); + // unknown-system-no-diagnostics + // unknown-warning@-2 {{unknown attribute 'init_priority' ignored}} Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // expected-error {{'init_priority' attribute takes one argument}} +// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}} Two coo[2] __attribute__((init_priority(100))); #if !defined(SYSTEM) -// expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + // expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + // unknown-warning@-3 {{unknown attribute 'init_priority' ignored}} #endif Two boo[2] __attribute__((init_priority(65536))); #if !defined(SYSTEM) -// expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + // expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} + // unknown-warning@-3 {{unknown attribute 'init_priority' ignored}} #endif Two koo[4] __attribute__((init_priority(1.13))); // expected-error {{'init_priority' attribute requires an integer constant}} +// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}} Two func() __attribute__((init_priority(1001))); // expected-error {{'init_priority' attribute only applies to variables}} +// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}} + int i __attribute__((init_priority(1001))); // expected-error {{can only use 'init_priority' attribute on file-scope definitions of objects of class type}} +// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}} int main() { - Two foo __attribute__((init_priority(1001))); // expected-error {{can only use 'init_priority' attribute on file-scope definitions of objects of class type}} + Two foo __attribute__((init_priority(1001))); // expected-error {{can onl
[PATCH] D91565: Guard init_priority attribute within libc++
zibi marked an inline comment as done. zibi added inline comments. Comment at: clang/test/SemaCXX/init-priority-attr.cpp:26 Two foo __attribute__((init_priority(101))) ( 5, 6 ); +#if defined(__MVS__) + #if defined(SYSTEM) aaron.ballman wrote: > Rather than using the preprocessor, you can assign a prefix to be checked to > `-verify`. e.g., `-verify=unknown` would allow you to do `// unknown-warning > {{unknown attribute 'init_priority' ignored}}` or `unknown-no-diagnostics` > that is only checked when `-verify=unknown`. > > I wonder if it would be cleaner to use that solution here instead of the > preprocessor by adding a new RUN line that's specific to AIX, and setting > some non-AIX triples for the other run lines. That simplifies a lot in the expanse of duplicating the run. Thank you Aaron. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91565/new/ https://reviews.llvm.org/D91565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D89801: [SystemZ][z/OS] Set short-enums as the default for z/OS
zibi added a comment. LGTM, though not sure why comment is referencing -fshort-enums=0. If '=0' is not significant perhaps delete it to remove confusion. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89801/new/ https://reviews.llvm.org/D89801 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits