Skip to content

Commit

Permalink
[clang] Change "bad" to "unsupported" in register type error (#111550)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DavidSpickett authored Oct 9, 2024
1 parent b9314a8 commit ef739e7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ Improvements to Clang's diagnostics

- Clang now omits warnings for extra parentheses in fold expressions with single expansion (#GH101863).

- The warning for an unsupported type for a named register variable is now phrased ``unsupported type for named register variable``,
instead of ``bad type for named register variable``. This makes it clear that the type is not supported at all, rather than being
suboptimal in some way the error fails to mention (#GH111550).

Improvements to Clang's time-trace
----------------------------------

Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -9379,7 +9379,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<
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Sema/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Sema/caret-diags-register-variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit ef739e7

Please sign in to comment.