Skip to content

[clang][Sema] Bad register variable type error should point to the type #110239

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

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ Bug Fixes in This Version
- Fixed a crash when trying to transform a dependent address space type. Fixes #GH101685.
- Fixed a crash when diagnosing format strings and encountering an empty
delimited escape sequence (e.g., ``"\o{}"``). #GH102218
- The warning emitted for an unsupported register variable type now points to
the unsupported type instead of the ``register`` keyword (#GH109776).

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 @@ -7957,7 +7957,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
}

if (!R->isIntegralType(Context) && !R->isPointerType()) {
Diag(D.getBeginLoc(), diag::err_asm_bad_register_type);
Diag(TInfo->getTypeLoc().getBeginLoc(), diag::err_asm_bad_register_type)
<< TInfo->getTypeLoc().getSourceRange();
NewVD->setInvalidDecl(true);
}
}
Expand Down
20 changes: 20 additions & 0 deletions clang/test/Sema/caret-diags-register-variable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: not %clang_cc1 -triple i386-pc-linux-gnu -std=c++11 -fsyntax-only -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=5 %s 2>&1 | FileCheck %s -strict-whitespace

struct foo {
int a;
};

//CHECK: {{.*}}: error: bad type for named register variable
//CHECK-NEXT: {{^}}register struct foo bar asm("esp");
//CHECK-NEXT: {{^}} ^~~~~~~~~~{{$}}
register struct foo bar asm("esp");

//CHECK: {{.*}}: error: register 'edi' unsuitable for global register variables on this target
//CHECK-NEXT: {{^}}register int r0 asm ("edi");
//CHECK-NEXT: {{^}} ^{{$}}
register int r0 asm ("edi");

//CHECK: {{.*}}: error: size of register 'esp' does not match variable size
//CHECK-NEXT: {{^}}register long long r1 asm ("esp");
//CHECK-NEXT: {{^}} ^{{$}}
register long long r1 asm ("esp");
Loading