[PATCH] D13834: Produce a better diagnostic for global register variables

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 16 14:51:37 PDT 2015


ahatanak created this revision.
ahatanak added a subscriber: cfe-commits.

clang doesn't print a very user-friendly message when an invalid register is used for a global register variable:

For example, when the following code is compiled,

$ cat f1.c
volatile register long long A asm ("rdi");

void foo1() {
  A = 1;
}

clang prints this error message:

$ clang -c f1.c
fatal error: error in backend: Invalid register name global variable

The code fails to compile because "rdi" isn't a valid register for global register variables on x86 (rsp, rbp, esp, and ebp are the only registers that are currently valid), but the diagnostic doesn't give much detail on why it is an error or which line of the source code is not correct because the error is detected in the backend.

This patch makes changes in Sema to catch this kind of error earlier. In addition, it errors out if the size of the register doesn't match the declared variable size.

e.g., volatile register int B asm ("rbp");

http://reviews.llvm.org/D13834

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGen/named_reg_global.c
  test/OpenMP/atomic_capture_codegen.cpp
  test/OpenMP/atomic_read_codegen.c
  test/OpenMP/atomic_update_codegen.cpp
  test/OpenMP/atomic_write_codegen.c
  test/OpenMP/for_loop_messages.cpp
  test/OpenMP/threadprivate_messages.cpp
  test/Sema/asm.c
  test/SemaCUDA/asm-constraints-mixed.cu

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13834.37645.patch
Type: text/x-patch
Size: 13079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151016/176de693/attachment.bin>


More information about the cfe-commits mailing list