[PATCH] D96853: [clang][AVR] Support variable decorator '__flash'

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 30 10:28:16 PDT 2021


Anastasia added a comment.

Btw is any pointer conversion between address space 1 and the default address space allowed? I.e. is the following code valid:

  __flash static const int var1[] = {111, 222, 333};
  void foo(int*);
  ....
  foo(var1);

or

  __flash static const int var1[] = {111, 222, 333};
  void foo(int*);
  ....
  foo((int*)var1);

?



================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2996
+  "qualifier '%select{const|volatile}0' is %select{needed|invalid}0 "
+  "for variables in address space '%2'">;
 def err_compound_literal_with_address_space : Error<
----------------
FYI I guess you don't need 3 parameters any more so it should be:

```
  "for variables in address space '%1'">;
```


================
Comment at: clang/lib/CodeGen/TargetInfo.cpp:8045
+                            diag::err_qualifier_with_address_space)
+          << 0 << 0 << "__flash";
+    return TargetCodeGenInfo::getGlobalVarAddressSpace(CGM, D);
----------------
ok,  now you should only need:

```
<< 0 <<  "__flash"; 
```


================
Comment at: clang/test/CodeGen/avr-flash.c:1
+// RUN: %clang_cc1 -triple avr -emit-llvm-only -verify %s
+
----------------
If you are only checking the diagnostics you should pass:

`-emit-llvm-only` -> `-syntax-only`

and also it should be moved to `clang/test/Sema`.


================
Comment at: clang/test/CodeGen/avr-flash.c:4
+int foo(int i, int j) {
+  static __flash int b[] = {4, 6, 1, 2, 5}; // expected-error {{qualifier 'const' is needed for variables in address space '__flash'}}
+  return b[j] + b[i];
----------------
Let's also test the `volatile` case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96853/new/

https://reviews.llvm.org/D96853



More information about the cfe-commits mailing list