[llvm-dev] Question about typeof builtin and address_space pointers

Y Song via llvm-dev llvm-dev at lists.llvm.org
Sat Nov 2 21:08:08 PDT 2019


Hi,

I have some questions about the following interaction between typeof
builtin and pointers with address space attribute.

-bash-4.4$ cat t2.c
int test(int __attribute__((address_space(1))) *p) {
#ifdef NO_TYPEOF
  int t = *p;
#else
  typeof(*p) t = *p;
#endif
  return t;
}
-bash-4.4$ clang -c t2.c
t2.c:5:14: error: automatic variable qualified with an address space
  typeof(*p) t = *p;
             ^
1 error generated.
-bash-4.4$ clang -DNO_TYPEOF -c t2.c
-bash-4.4$

The compiler is latest trunk. I built a release version with assertion
on, but assertion probably should not matter here.

>From the above example, an error will appear with typeof of the
pointer dereference, but will be okay if using type 'int' directly.

Is this the expected behavior? What exactly 'typeof' builtiin does here?
Some clarification will be really appreciated.

Thanks!

Yonghong


More information about the llvm-dev mailing list