https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/110239
>From 84946607fc58927b1b44da2b70566abca041bbfb Mon Sep 17 00:00:00 2001 From: David Spickett <david.spick...@linaro.org> Date: Fri, 27 Sep 2024 10:19:19 +0000 Subject: [PATCH] [clang][Sema] Bad register variable type error should point to the type ...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. So I've added a new caret test file as I see has been done for other error types. --- clang/lib/Sema/SemaDecl.cpp | 3 ++- .../Sema/caret-diags-register-variable.cpp | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/caret-diags-register-variable.cpp diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 1bf0e800a36228..048ac9c22eef50 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7949,7 +7949,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); 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..09893341717c8e --- /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"); // expected-error {{bad type for named register variable}} + +//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"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits