Issue 109192
Summary Unable to use clang header with GCC <9.3 with `-Werror`
Labels
Assignees
Reporter jabraham17
    Due to a bug in GCC, any compilation with GCC older than 9.3 that uses `clang/Basic/PointerAuthOptions.h` throws a warning:

"‘clang::PointerAuthSchema::DiscriminationKind’ is too small to hold all values of ‘enum class clang::PointerAuthSchema::Discrimination’"

The [GCC Bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242) was fixed in 9.3 (also 8.4), the following shows the issue with various compilers: https://godbolt.org/z/Ko48cbj1T. 

While this is only a warning, it is now impossible to compile code with `-Werror`, because there is no separate warning flag for this warning. So the warning cannot be turned off and it cannot be marked `-Wno-error=...`.

This is a regression in clang 19, caused by https://github.com/llvm/llvm-project/pull/93906.

The following patch can be applied to `clang/Basic/PointerAuthOptions.h` and is sufficient to workaround the issue, and I strongly feel this should be included in a point release

```patch
@@ -63,17 +63,17 @@
   };
 
 private:
-  Kind TheKind : 2;
+  unsigned TheKind : 2;
   unsigned IsAddressDiscriminated : 1;
   unsigned IsIsaPointer : 1;
   unsigned AuthenticatesNullValues : 1;
-  PointerAuthenticationMode SelectedAuthenticationMode : 2;
-  Discrimination DiscriminationKind : 2;
+  unsigned SelectedAuthenticationMode : 2;
+  unsigned DiscriminationKind : 2;
   unsigned Key : 2;
   unsigned ConstantDiscriminator : 16;
 
 public:
-  PointerAuthSchema() : TheKind(Kind::None) {}
+  PointerAuthSchema() : TheKind(llvm::to_underlying(Kind::None)) {}
 
   PointerAuthSchema(
       ARM8_3Key Key, bool IsAddressDiscriminated,
@@ -81,11 +81,11 @@
       Discrimination OtherDiscrimination,
       std::optional<uint16_t> ConstantDiscriminatorOrNone = std::nullopt,
       bool IsIsaPointer = false, bool AuthenticatesNullValues = false)
-      : TheKind(Kind::ARM8_3), IsAddressDiscriminated(IsAddressDiscriminated),
+      : TheKind(llvm::to_underlying(Kind::ARM8_3)), IsAddressDiscriminated(IsAddressDiscriminated),
         IsIsaPointer(IsIsaPointer),
         AuthenticatesNullValues(AuthenticatesNullValues),
-        SelectedAuthenticationMode(AuthenticationMode),
-        DiscriminationKind(OtherDiscrimination), Key(llvm::to_underlying(Key)) {
+        SelectedAuthenticationMode(llvm::to_underlying(AuthenticationMode)),
+        DiscriminationKind(llvm::to_underlying(OtherDiscrimination)), Key(llvm::to_underlying(Key)) {
     assert((getOtherDiscrimination() != Discrimination::Constant ||
             ConstantDiscriminatorOrNone) &&
            "constant discrimination requires a constant!");
@@ -103,7 +103,7 @@
                           OtherDiscrimination, ConstantDiscriminatorOrNone,
                           IsIsaPointer, AuthenticatesNullValues) {}
 
-  Kind getKind() const { return TheKind; }
+  Kind getKind() const { return Kind(TheKind); }
 
   explicit operator bool() const { return isEnabled(); }
 
@@ -130,7 +130,7 @@
 
   Discrimination getOtherDiscrimination() const {
     assert(getKind() != Kind::None);
-    return DiscriminationKind;
+    return Discrimination(DiscriminationKind);
   }
 
   uint16_t getConstantDiscrimination() const {
@@ -149,7 +149,7 @@
   }
 
   PointerAuthenticationMode getAuthenticationMode() const {
-    return SelectedAuthenticationMode;
+    return PointerAuthenticationMode(SelectedAuthenticationMode);
   }
 
   ARM8_3Key getARM8_3Key() const {

```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to