[clang] [clang] Fix `gnu::init_priority` attribute handling for reserved values (PR #121577)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 16 08:56:13 PST 2025


================
@@ -3591,15 +3591,20 @@ static void handleInitPriorityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
     return;
   }
 
+  if (prioritynum < 0 || prioritynum > 65535) {
+    S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
+        << E->getSourceRange() << AL << 0 << 65535;
+    AL.setInvalid();
+    return;
+  }
+
   // Only perform the priority check if the attribute is outside of a system
   // header. Values <= 100 are reserved for the implementation, and libc++
   // benefits from being able to specify values in that range.
-  if ((prioritynum < 101 || prioritynum > 65535) &&
+  if (prioritynum < 101 &&
       !S.getSourceManager().isInSystemHeader(AL.getLoc())) {
-    S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
----------------
erichkeane wrote:

Since this is changing to a warning, the `isInSystemHeader` check no longer needs to happen (as we suppress system header warnings anyway).

https://github.com/llvm/llvm-project/pull/121577


More information about the cfe-commits mailing list