Skip to content

Commit 782a2d4

Browse files
[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.
1 parent 6636f32 commit 782a2d4

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ Bug Fixes in This Version
395395
- Fixed a crash when trying to transform a dependent address space type. Fixes #GH101685.
396396
- Fixed a crash when diagnosing format strings and encountering an empty
397397
delimited escape sequence (e.g., ``"\o{}"``). #GH102218
398+
- The warning emitted for an unsupported register variable type now points to
399+
the unsupported type instead of the ``register`` keyword (#GH109776).
398400

399401
Bug Fixes to Compiler Builtins
400402
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7957,7 +7957,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
79577957
}
79587958

79597959
if (!R->isIntegralType(Context) && !R->isPointerType()) {
7960-
Diag(D.getBeginLoc(), diag::err_asm_bad_register_type);
7960+
Diag(TInfo->getTypeLoc().getBeginLoc(), diag::err_asm_bad_register_type)
7961+
<< TInfo->getTypeLoc().getSourceRange();
79617962
NewVD->setInvalidDecl(true);
79627963
}
79637964
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// 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
2+
3+
struct foo {
4+
int a;
5+
};
6+
7+
//CHECK: {{.*}}: error: bad type for named register variable
8+
//CHECK-NEXT: {{^}}register struct foo bar asm("esp");
9+
//CHECK-NEXT: {{^}} ^~~~~~~~~~{{$}}
10+
register struct foo bar asm("esp");
11+
12+
//CHECK: {{.*}}: error: register 'edi' unsuitable for global register variables on this target
13+
//CHECK-NEXT: {{^}}register int r0 asm ("edi");
14+
//CHECK-NEXT: {{^}} ^{{$}}
15+
register int r0 asm ("edi");
16+
17+
//CHECK: {{.*}}: error: size of register 'esp' does not match variable size
18+
//CHECK-NEXT: {{^}}register long long r1 asm ("esp");
19+
//CHECK-NEXT: {{^}} ^{{$}}
20+
register long long r1 asm ("esp");

0 commit comments

Comments
 (0)