Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Change "bad" to "unsupported" in register type error #111550

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DavidSpickett
Copy link
Collaborator

This is maybe a personal take but I expect "bad" to either mean:

  • Allowed but not ideal, like a "bad" memory alignment might work but it is slow.
  • The tool won't allow it but is going to tell me why it didn't.

The current error doesn't elaborate so I think it's best we just say "unsupported" instead. This is clear that the type used is not allowed at all.

This is maybe a personal take but I expect "bad" to either mean:
* Allowed but not ideal, like a "bad" memory alignment might work
  but it is slow.
* The tool won't allow it but is going to tell me why it didn't.

The current error doesn't elaborate so I think it's best we just
say "unsupported" instead. This is clear that the type used is
not allowed at all.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 8, 2024

@llvm/pr-subscribers-clang

Author: David Spickett (DavidSpickett)

Changes

This is maybe a personal take but I expect "bad" to either mean:

  • Allowed but not ideal, like a "bad" memory alignment might work but it is slow.
  • The tool won't allow it but is going to tell me why it didn't.

The current error doesn't elaborate so I think it's best we just say "unsupported" instead. This is clear that the type used is not allowed at all.


Full diff: https://github.com/llvm/llvm-project/pull/111550.diff

4 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2-1)
  • (modified) clang/lib/Sema/SemaDecl.cpp (+2-1)
  • (modified) clang/test/Sema/asm.c (+2-2)
  • (modified) clang/test/Sema/caret-diags-register-variable.cpp (+1-1)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 583475327c5227..82588cea4155c1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9386,7 +9386,8 @@ let CategoryName = "Inline Assembly Issue" in {
     "global register variables on this target">;
   def err_asm_register_size_mismatch : Error<"size of register '%0' does not "
     "match variable size">;
-  def err_asm_bad_register_type : Error<"bad type for named register variable">;
+  def err_asm_unsupported_register_type : Error<
+    "unsupported type for named register variable">;
   def err_asm_invalid_input_size : Error<
     "invalid input size for constraint '%0'">;
   def err_asm_invalid_output_size : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 83d71913f8635e..072f43d360ee1c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7961,7 +7961,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
       }
 
       if (!R->isIntegralType(Context) && !R->isPointerType()) {
-        Diag(TInfo->getTypeLoc().getBeginLoc(), diag::err_asm_bad_register_type)
+        Diag(TInfo->getTypeLoc().getBeginLoc(),
+             diag::err_asm_unsupported_register_type)
             << TInfo->getTypeLoc().getSourceRange();
         NewVD->setInvalidDecl(true);
       }
diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index 630a5e85dd9131..6cd95c71604d44 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -191,8 +191,8 @@ void iOutputConstraint(int x){
 struct foo {
   int a;
 };
-register struct foo bar asm("esp"); // expected-error {{bad type for named register variable}}
-register float baz asm("esp"); // expected-error {{bad type for named register variable}}
+register struct foo bar asm("esp"); // expected-error {{unsupported type for named register variable}}
+register float baz asm("esp"); // expected-error {{unsupported type for named register variable}}
 
 register int r0 asm ("edi"); // expected-error {{register 'edi' unsuitable for global register variables on this target}}
 register long long r1 asm ("esp"); // expected-error {{size of register 'esp' does not match variable size}}
diff --git a/clang/test/Sema/caret-diags-register-variable.cpp b/clang/test/Sema/caret-diags-register-variable.cpp
index 24f5061d4b4d2c..c2d2fbe0c581ae 100644
--- a/clang/test/Sema/caret-diags-register-variable.cpp
+++ b/clang/test/Sema/caret-diags-register-variable.cpp
@@ -4,7 +4,7 @@ struct foo {
   int a;
 };
 
-//CHECK: {{.*}}: error: bad type for named register variable
+//CHECK: {{.*}}: error: unsupported type for named register variable
 //CHECK-NEXT: {{^}}register struct foo bar asm("esp");
 //CHECK-NEXT: {{^}}         ^~~~~~~~~~{{$}}
 register struct foo bar asm("esp");

Copy link
Contributor

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

(I’ve definitely seen ‘bad X’ in other places before, and I’ve personally never really had a problem w/ that sort of wording, but I also can’t deny that ‘unsupported X’ is unquestionably clearer ;Þ)

@Sirraide
Copy link
Contributor

Sirraide commented Oct 8, 2024

I think we also might want to add a release note for this since this is technically improving a diagnostic, if only in a very minor way... I’m not sure if we have a clear-cut policy for that when it comes to changes that only change the wording of a diagnostic.

@DavidSpickett
Copy link
Collaborator Author

Added a release note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants