<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109192>109192</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unable to use clang header with GCC <9.3 with `-Werror`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jabraham17
</td>
</tr>
</table>
<pre>
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 {
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykWF-TmzgS_zTyS9dQIDwMPPhhbMdXqdRuri6528eUgDYoK0s-Sczs5NNfSfwx2OBMbinXWEbqf7_u_kkaZgyvJOKGPG7J437FGlsrvfnOcs1qdoqeVrkq3zb7BsEqYJA3FXAJ_9jtCN0Bk29QqNOZC2a5kvDKbe3mQIkSNdiaSciC2A0sNAYNkCQsBJMVoYctM7wg9PBPxaVF_dzY-vPZqTFBTZIQbK3VqwEGr0xLLisSP5NwT8L-L6XkAyVpSLK0VRk_k_h5pO1LUeOJta_33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