[llvm-branch-commits] [clang] 393e6e4 - Support macro deprecation #pragma clang deprecated

2021-07-29 Thread Chris Bieneman via llvm-branch-commits

Author: Chris Bieneman
Date: 2021-07-29T09:11:14-05:00
New Revision: 393e6e4cbc05f589c4dd75dbfae79ee44eb1a5f5

URL: 
https://github.com/llvm/llvm-project/commit/393e6e4cbc05f589c4dd75dbfae79ee44eb1a5f5
DIFF: 
https://github.com/llvm/llvm-project/commit/393e6e4cbc05f589c4dd75dbfae79ee44eb1a5f5.diff

LOG: Support macro deprecation #pragma clang deprecated

This patch adds `#pragma clang deprecated` to enable deprecation of
preprocessor macros.

The macro must be defined before `#pragma clang deprecated`. When
deprecating a macro a custom message may be optionally provided.

Warnings are emitted at the use site of a deprecated macro, and can be
controlled via the `-Wdeprecated` warning group.

This patch takes some rough inspiration and a few lines of code from
https://reviews.llvm.org/D67935.

Differential Revision: https://reviews.llvm.org/D106732

Added: 
clang/test/Lexer/deprecate-macro.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPExpressions.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 462aa89ea789a..8dafcb2f9a724 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3887,6 +3887,24 @@ Since the size of ``buffer`` can't be known at compile 
time, Clang will fold
 as ``__builtin_dynamic_object_size(buffer, 0)``, Clang will fold it into
 ``size``, providing some extra runtime safety.
 
+Deprecating Macros
+==
+
+Clang supports the pragma ``#pragma clang deprecated``, which can be used to
+provide deprecation warnings for macro uses. For example:
+
+.. code-block:: c
+   #define MIN(x, y) x < y ? x : y
+   #pragma clang deprecated(MIN, "use std::min instead")
+
+   void min(int a, int b) {
+ return MIN(a, b); // warning: MIN is deprecated: use std::min instead
+   }
+
+``#pragma clang deprecated`` should be preferred for this purpose over
+``#pragma GCC warning`` because the warning can be controlled with
+``-Wdeprecated``.
+
 Extended Integer Types
 ==
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 4b4928a7a00e6..6857c889b72b6 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -184,6 +184,7 @@ def DeprecatedThisCapture : 
DiagGroup<"deprecated-this-capture">;
 def DeprecatedVolatile : DiagGroup<"deprecated-volatile">;
 def DeprecatedWritableStr : DiagGroup<"deprecated-writable-strings",
   [CXX11CompatDeprecatedWritableStr]>;
+def DeprecatedPragma : DiagGroup<"deprecated-pragma">;
 // FIXME: Why is DeprecatedImplementations not in this group?
 def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
   DeprecatedArrayCompare,
@@ -198,6 +199,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedEnumEnumConversion,
   DeprecatedEnumFloatConversion,
   DeprecatedIncrementBool,
+  DeprecatedPragma,
   DeprecatedRegister,
   DeprecatedThisCapture,
   DeprecatedVolatile,

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ce6d0d0394b48..174f6c3dfd4c6 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -519,6 +519,11 @@ def warn_pragma_warning_expected_number :
   ExtWarn<"#pragma warning expected a warning number">,
   InGroup;
 
+// - #pragma deprecated(...)
+def warn_pragma_deprecated_macro_use :
+  ExtWarn<"macro %0 has been marked as deprecated%select{|: %2}1">,
+  InGroup;
+
 // - #pragma execution_character_set(...)
 def warn_pragma_exec_charset_expected :
   ExtWarn<"#pragma execution_character_set expected '%0'">,

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index f2379c7ddfbd1..d75d43f0398d7 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -121,7 +121,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   // True if this is a mangled OpenMP variant name.
   unsigned IsMangledOpenMPVariantName : 1;
 
-  // 28 bits left in a 64

[llvm-branch-commits] [clang] 997d922 - This patch adds `#pragma clang header_unsafe` to enable flagging macros

2021-07-29 Thread Chris Bieneman via llvm-branch-commits

Author: Chris Bieneman
Date: 2021-07-29T10:10:51-05:00
New Revision: 997d9222f2ffa08c646076f2154993484e1ade98

URL: 
https://github.com/llvm/llvm-project/commit/997d9222f2ffa08c646076f2154993484e1ade98
DIFF: 
https://github.com/llvm/llvm-project/commit/997d9222f2ffa08c646076f2154993484e1ade98.diff

LOG: This patch adds `#pragma clang header_unsafe` to enable flagging macros
as unsafe for header use. This is to allow macros that may have ABI
implications to be avoided in headers that have ABI stability promises.

Using macros in headers (particularly public headers) can cause a
variety of issues relating to ABI and modules. This new pragma logs
warnings when using annotated macros outside the main source file.

This warning is added under a new diagnostics group -Wpedantic-macros.

Added: 
clang/test/Lexer/Inputs/unsafe-macro-2.h
clang/test/Lexer/Inputs/unsafe-macro.h
clang/test/Lexer/unsafe-macro.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 8dafcb2f9a724..952db626535f4 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3492,8 +3492,7 @@ The pragma can take two values: ``on`` and ``off``.
 float v = t + z;
   }
 
-
-``#pragma clang fp contract`` specifies whether the compiler should
+x2``#pragma clang fp contract`` specifies whether the compiler should
 contract a multiply and an addition (or subtraction) into a fused FMA
 operation when supported by the target.
 
@@ -3905,6 +3904,28 @@ provide deprecation warnings for macro uses. For example:
 ``#pragma GCC warning`` because the warning can be controlled with
 ``-Wdeprecated``.
 
+Header Unsafe Macros
+
+
+Clang supports the pragma ``#pragma clang header_unsafe``, which can be used to
+mark macros as unsafe to use in headers. This can be valuable when providing
+headers with ABI stability requirements. For example:
+
+.. code-block:: c
+   #define TARGET_ARM 1
+   #pragma clang header_unsafe(TARGET_ARM, "")
+
+   /// Foo.h
+   struct Foo {
+   #if TARGET_ARM // warning: TARGET_ARM is marked unsafe in headers: 
+ uint32_t X;
+   #else
+ uint64_t X;
+   #endif
+   };
+
+This warning is controlled by ``-Wpedantic-macros``.
+
 Extended Integer Types
 ==
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6857c889b72b6..bd1cc3c7ff3cd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1305,3 +1305,7 @@ def WebAssemblyExceptionSpec : 
DiagGroup<"wasm-exception-spec">;
 def RTTI : DiagGroup<"rtti">;
 
 def OpenCLCoreFeaturesDiagGroup : DiagGroup<"pedantic-core-features">;
+
+// Warnings and extensions to make preprocessor macro usage pedantic
+def PedanticMacros : DiagGroup<"pedantic-macros",
+[DeprecatedPragma, MacroRedefined, BuiltinMacroRedefined]>;

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 174f6c3dfd4c6..ea4f0b2d5bb0c 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -524,6 +524,12 @@ def warn_pragma_deprecated_macro_use :
   ExtWarn<"macro %0 has been marked as deprecated%select{|: %2}1">,
   InGroup;
 
+// - #pragma clang header_unsafe(...)
+def warn_pragma_header_unsafe_macro_use :
+  ExtWarn<"macro %0 has been marked as unsafe for use in headers"
+  "%select{|: %2}1">,
+  InGroup;
+
 // - #pragma execution_character_set(...)
 def warn_pragma_exec_charset_expected :
   ExtWarn<"#pragma execution_character_set expected '%0'">,

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index d75d43f0398d7..599d10f8bd00a 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -124,7 +124,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   // True if this is a deprecated macro
   unsigned IsDeprecatedMacro : 1;
 
-  // 24 bits left in a 64-bit word.
+  // True if this macro is unsafe in headers
+  unsigned IsHeaderUnsafe : 1;
+
+  // 23 bits left in a 64-bit word.
 
   // Managed by the language front-end.
   void *FETokenInfo = nullptr;
@@ -138,7 +141,7 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
 NeedsHandleIdentifier(false), IsFromAST(false), 
ChangedAfterLoad(false),
 FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
 IsModulesImport(false), 

[llvm-branch-commits] [clang] 267dc10 - Implement #pragma clang final extension

2021-07-29 Thread Chris Bieneman via llvm-branch-commits

Author: Chris Bieneman
Date: 2021-07-29T11:19:25-05:00
New Revision: 267dc10d53f124dceeccee042f61e6e6624f6d4c

URL: 
https://github.com/llvm/llvm-project/commit/267dc10d53f124dceeccee042f61e6e6624f6d4c
DIFF: 
https://github.com/llvm/llvm-project/commit/267dc10d53f124dceeccee042f61e6e6624f6d4c.diff

LOG: Implement #pragma clang final extension

This patch adds a new preprocessor extension ``#pragma clang final``
which enables warning on undefinition and re-definition of macros.

The intent of this warning is to extend beyond ``-Wmacro-redefined`` to
warn against any and all alterations to macros that are marked `final`.

This warning is part of the ``-Wpedantic-macros`` diagnostics group.

Added: 
clang/test/Lexer/final-macro.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/Pragma.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 952db626535f..54cb8164 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3926,6 +3926,23 @@ headers with ABI stability requirements. For example:
 
 This warning is controlled by ``-Wpedantic-macros``.
 
+Final Macros
+
+
+Clang supports the pragma ``#pragma clang final``, which can be used to
+mark macros as final, meaning they cannot be undef'd or re-defined. For 
example:
+
+.. code-block:: c
+   #define FINAL_MACRO 1
+   #pragma clang final(FINAL_MACRO)
+
+   #undef FINAL_MACRO  // warning: FINAL_MACRO is marked final and should not 
be undefined
+   #define FINAL_MACRO // warning: FINAL_MACRO is marked final and should not 
be redefined
+
+This is useful for enforcing system-provided macros that should not be altered
+in user headers or code. This is controlled by ``-Wabi-stability`` and implies
+the related ``-Wmacro-redefined``.
+
 Extended Integer Types
 ==
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index bd1cc3c7ff3c..341e120cf139 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1308,4 +1308,4 @@ def OpenCLCoreFeaturesDiagGroup : 
DiagGroup<"pedantic-core-features">;
 
 // Warnings and extensions to make preprocessor macro usage pedantic
 def PedanticMacros : DiagGroup<"pedantic-macros",
-[DeprecatedPragma, MacroRedefined, BuiltinMacroRedefined]>;
+[DeprecatedPragma, MacroRedefined, BuiltinMacroRedefined]>;
\ No newline at end of file

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ea4f0b2d5bb0..e9db43e236e2 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -530,6 +530,12 @@ def warn_pragma_header_unsafe_macro_use :
   "%select{|: %2}1">,
   InGroup;
 
+// - #pragma clang final(...)
+def warn_pragma_final_macro :
+  ExtWarn<"macro %0 has been marked as final and should not be "
+  "%select{un|re}1defined">,
+  InGroup;
+
 // - #pragma execution_character_set(...)
 def warn_pragma_exec_charset_expected :
   ExtWarn<"#pragma execution_character_set expected '%0'">,

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 599d10f8bd00..67b824e79464 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -127,7 +127,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   // True if this macro is unsafe in headers
   unsigned IsHeaderUnsafe : 1;
 
-  // 23 bits left in a 64-bit word.
+  // True if this macro is final
+  unsigned IsFinal : 1;
+
+  // 22 bits left in a 64-bit word.
 
   // Managed by the language front-end.
   void *FETokenInfo = nullptr;
@@ -141,7 +144,7 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
 NeedsHandleIdentifier(false), IsFromAST(false), 
ChangedAfterLoad(false),
 FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
 IsModulesImport(false), IsMangledOpenMPVariantName(false),
-IsDeprecatedMacro(false), IsHeaderUnsafe(false) {}
+IsDeprecatedMacro(false), IsHeaderUnsafe(false), IsFinal(false) {}
 
 public:
   IdentifierInfo(const IdentifierInfo &) = delete;
@@ -227,6 +230,12 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   RecomputeNeedsHandleIdentifier();
   }
 
+  bool isFinal() const { return IsFinal; }
+
+  void setIsFinal(bool Val) {
+IsFinal = Val;
+  }
+
   /// If this is a source-language token (e.g. 'for'), this API
   /// can be used to cause the lexer to map identifiers to source-language
   

[llvm-branch-commits] [llvm-branch] r277617 - [docs] Release Notes: autoconf has been removed

2016-08-11 Thread Chris Bieneman via llvm-branch-commits
Author: cbieneman
Date: Wed Aug  3 13:08:14 2016
New Revision: 277617

URL: http://llvm.org/viewvc/llvm-project?rev=277617&view=rev
Log:
[docs] Release Notes: autoconf has been removed

Fleshing out the note about the autoconf build system being removed and 
pointing to CMake documentation.

Modified:
llvm/branches/release_39/docs/ReleaseNotes.rst

Modified: llvm/branches/release_39/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/docs/ReleaseNotes.rst?rev=277617&r1=277616&r2=277617&view=diff
==
--- llvm/branches/release_39/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_39/docs/ReleaseNotes.rst Wed Aug  3 13:08:14 2016
@@ -40,7 +40,10 @@ Non-comprehensive list of changes in thi
 
 * There is no longer a "global context" available in LLVM, except for the C 
API.
 
-* .. note about autoconf build having been removed.
+* The autoconf build system has been removed in favor of CMake. LLVM 3.9
+  requires CMake 3.4.3 or later to build. For information about using CMake
+  please see the documentation on :doc:`CMake`. For information about the CMake
+  language there is also a :doc:`CMakePrimer` document available.
 
 * .. note about C API functions LLVMParseBitcode,
LLVMParseBitcodeInContext, LLVMGetBitcodeModuleInContext and


___
llvm-branch-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [cfe-branch] r368894 - Merging release note update in r368874

2019-08-20 Thread Chris Bieneman via llvm-branch-commits
Author: cbieneman
Date: Wed Aug 14 11:11:11 2019
New Revision: 368894

URL: http://llvm.org/viewvc/llvm-project?rev=368894&view=rev
Log:
Merging release note update in r368874

Modified:
cfe/branches/release_90/   (props changed)
cfe/branches/release_90/docs/ReleaseNotes.rst

Propchange: cfe/branches/release_90/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 14 11:11:11 2019
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:366429,366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323,367387,367403,367520,367530,367661,367675,367802,367823,367906,368104,368202,368552,368561
+/cfe/trunk:366429,366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323,367387,367403,367520,367530,367661,367675,367802,367823,367906,368104,368202,368552,368561,368874
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_90/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/docs/ReleaseNotes.rst?rev=368894&r1=368893&r2=368894&view=diff
==
--- cfe/branches/release_90/docs/ReleaseNotes.rst (original)
+++ cfe/branches/release_90/docs/ReleaseNotes.rst Wed Aug 14 11:11:11 2019
@@ -192,7 +192,15 @@ release of Clang. Users of the build sys
   install-clang-headers target now installs clang's API headers (corresponding
   to its libraries), which is consistent with the install-llvm-headers target.
 
--  ...
+- In 9.0.0 and later Clang added a new target, clang-cpp, which generates a
+  shared library comprised of all the clang component libraries and exporting
+  the clang C++ APIs. Additionally the build system gained the new
+  "CLANG_LINK_CLANG_DYLIB" option, which defaults Off, and when set to On, will
+  force clang (and clang-based tools) to link the clang-cpp library instead of
+  statically linking clang's components. This option will reduce the size of
+  binary distributions at the expense of compiler performance.
+
+- ...
 
 AST Matchers
 


___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [cfe-branch] r369017 - Correcting clang-cpp release not to spcify supported targets.

2019-08-20 Thread Chris Bieneman via llvm-branch-commits
Author: cbieneman
Date: Thu Aug 15 09:54:13 2019
New Revision: 369017

URL: http://llvm.org/viewvc/llvm-project?rev=369017&view=rev
Log:
Correcting clang-cpp release not to spcify supported targets.

Modified:
cfe/branches/release_90/docs/ReleaseNotes.rst

Modified: cfe/branches/release_90/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/docs/ReleaseNotes.rst?rev=369017&r1=369016&r2=369017&view=diff
==
--- cfe/branches/release_90/docs/ReleaseNotes.rst (original)
+++ cfe/branches/release_90/docs/ReleaseNotes.rst Thu Aug 15 09:54:13 2019
@@ -192,13 +192,13 @@ release of Clang. Users of the build sys
   install-clang-headers target now installs clang's API headers (corresponding
   to its libraries), which is consistent with the install-llvm-headers target.
 
-- In 9.0.0 and later Clang added a new target, clang-cpp, which generates a
-  shared library comprised of all the clang component libraries and exporting
-  the clang C++ APIs. Additionally the build system gained the new
-  "CLANG_LINK_CLANG_DYLIB" option, which defaults Off, and when set to On, will
-  force clang (and clang-based tools) to link the clang-cpp library instead of
-  statically linking clang's components. This option will reduce the size of
-  binary distributions at the expense of compiler performance.
+- In 9.0.0 and later Clang added a new target on Linux/Unix systems, clang-cpp,
+  which generates a shared library comprised of all the clang component
+  libraries and exporting the clang C++ APIs. Additionally the build system
+  gained the new "CLANG_LINK_CLANG_DYLIB" option, which defaults Off, and when
+  set to On, will force clang (and clang-based tools) to link the clang-cpp
+  library instead of statically linking clang's components. This option will
+  reduce the size of binary distributions at the expense of compiler 
performance.
 
 - ...
 


___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits