[clang] 782a2d4 - [clang][Sema] Bad register variable type error should point to the type (#110239)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 8 03:01:43 PDT 2024
Author: David Spickett
Date: 2024-10-08T11:01:40+01:00
New Revision: 782a2d40005a2820f05c9801aff816c01789c7be
URL: https://github.com/llvm/llvm-project/commit/782a2d40005a2820f05c9801aff816c01789c7be
DIFF: https://github.com/llvm/llvm-project/commit/782a2d40005a2820f05c9801aff816c01789c7be.diff
LOG: [clang][Sema] Bad register variable type error should point to the type (#110239)
...not the register keyword. Fixes #109776.
Until now the error was only tested in clang/test/Sema/asm.c, where you
can't check for the "^" character. I've added a new caret test file as I
see has been done for other error types.
Added:
clang/test/Sema/caret-diags-register-variable.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 10644c9854270e..05bd74710dd7c8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5c4e0562152c5b..4eaa3913f4344a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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);
}
}
diff --git a/clang/test/Sema/caret-diags-register-variable.cpp b/clang/test/Sema/caret-diags-register-variable.cpp
new file mode 100644
index 00000000000000..24f5061d4b4d2c
--- /dev/null
+++ b/clang/test/Sema/caret-diags-register-variable.cpp
@@ -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");
More information about the cfe-commits
mailing list