aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.dg
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-06-23 18:24:07 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2022-06-24 20:49:58 +0200
commit91418c42089cd1cbe71edcd6b2f5b26559819372 (patch)
tree6419c5301b4fb08e5b0cac64baddc66f7e3acadf /gcc/testsuite/gdc.dg
parent8288cd635fa0bd75a8c5f25c7a90d4a7a4acec81 (diff)
downloadgcc-91418c42089cd1cbe71edcd6b2f5b26559819372.zip
gcc-91418c42089cd1cbe71edcd6b2f5b26559819372.tar.gz
gcc-91418c42089cd1cbe71edcd6b2f5b26559819372.tar.bz2
d: Add `@register' attribute to compiler and library.
The `@register` attribute specifies that a local or `__gshared` variable is to be given a register storage-class in the C sense of the term, and will be placed into a register named `registerName`. The variable needs to boiled down to a data type that fits the target register. It also cannot have either thread-local or `extern` storage. It is an error to take the address of a register variable. PR d/105413 gcc/d/ChangeLog: * d-attribs.cc (d_handle_register_attribute): New function. (d_langhook_attribute_table): Add register attribute. * d-codegen.cc (d_mark_addressable): Error if taken address of register variable. (build_frame_type): Error if register variable has non-local references. * d-tree.h (d_mark_addressable): Add complain parameter. * decl.cc (get_symbol_decl): Mark register varibles DECL_REGISTER. Error when register variable declared thread-local or extern. * expr.cc (ExprVisitor::visit (IndexExp *)): Don't complain about marking register vectors as addressable in an ARRAY_REF. libphobos/ChangeLog: * libdruntime/gcc/attributes.d (register): Define. gcc/testsuite/ChangeLog: * gdc.dg/attr_register1.d: New test. * gdc.dg/attr_register2.d: New test. * gdc.dg/attr_register3.d: New test.
Diffstat (limited to 'gcc/testsuite/gdc.dg')
-rw-r--r--gcc/testsuite/gdc.dg/attr_register1.d55
-rw-r--r--gcc/testsuite/gdc.dg/attr_register2.d11
-rw-r--r--gcc/testsuite/gdc.dg/attr_register3.d22
3 files changed, 88 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.dg/attr_register1.d b/gcc/testsuite/gdc.dg/attr_register1.d
new file mode 100644
index 0000000..01fc245
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/attr_register1.d
@@ -0,0 +1,55 @@
+// { dg-do compile }
+
+import gcc.attributes;
+
+@attribute("register", null) int var1; // { dg-error "attribute argument not a string constant" }
+
+@attribute("register", "") int var2; // { dg-error "register name not specified for .var2." }
+
+@attribute("register", "invalid") __gshared int var3; // { dg-error "invalid register name for .var3." }
+
+void f1(ref int r) { }
+
+void test1()
+{
+ @register("ref") int var6;
+ f1(var6); // { dg-error "address of explicit register variable .var6. requested" }
+}
+
+void f2(out int r) { }
+
+void test2()
+{
+ @register("out") int var7;
+ f2(var7); // { dg-error "address of explicit register variable .var7. requested" }
+}
+
+void f3(lazy int r) { }
+
+void test3()
+{
+ @register("lazy") int var8; // { dg-error "explicit register variable .var8. cannot be used in nested function" }
+ f3(var8);
+}
+
+void test4()
+{
+ @register("addr") int var9;
+ auto ptr3 = &var9; // { dg-error "address of explicit register variable .var9. requested" }
+}
+
+ref int test5()
+{
+ @register("refreturn") __gshared int var10; // { dg-error "invalid register name" }
+ return var10; // { dg-error "address of explicit register variable .var10. requested" }
+}
+
+auto test6()
+{
+ @register("closure") int var11; // { dg-error "explicit register variable .var11. cannot be used in nested function" }
+ int nested()
+ {
+ return var11;
+ }
+ return &nested;
+}
diff --git a/gcc/testsuite/gdc.dg/attr_register2.d b/gcc/testsuite/gdc.dg/attr_register2.d
new file mode 100644
index 0000000..9061a64
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/attr_register2.d
@@ -0,0 +1,11 @@
+// { dg-do compile { target x86_64-*-* } }
+
+import gcc.attributes;
+
+@register("ebx") static int var1 = void; // { dg-error "explicit register variable .var1. declared thread local" }
+
+@register("ebx") extern int var2; // { dg-error "explicit register variable .var2. declared .extern." }
+
+@register("r12") __gshared int var3 = 0x2a; // { dg-error "global register variable has initial value" }
+
+@register("r12") __gshared int[256] var4 = void; // { dg-error "data type of .var4. isn.t suitable for a register" }
diff --git a/gcc/testsuite/gdc.dg/attr_register3.d b/gcc/testsuite/gdc.dg/attr_register3.d
new file mode 100644
index 0000000..706a399
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/attr_register3.d
@@ -0,0 +1,22 @@
+// { dg-do compile }
+// { dg-options "-Wall -O2 -fdump-tree-optimized" }
+
+import gcc.attributes;
+
+pragma(inline, true)
+void syscall()(int val)
+{
+ @register("4") int reg = val;
+ asm { "/* Some Code %0 */" :: "r" (reg); }
+}
+
+void do_syscalls()
+{
+ for (int s = 0; s < 2; s++)
+ {
+ syscall (0);
+ syscall (1);
+ }
+}
+
+// { dg-final { scan-tree-dump-times "reg = " 4 "optimized" } }