(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
attr-access-2.c
       1  /* PR 50584 - No warning for passing small array to C99 static array declarator
       2     Exercise interaction between explicit attribute access and VLA parameters.
       3     { dg-do compile }
       4     { dg-options "-Wall" } */
       5  
       6  #define RW(...) __attribute__ ((access (read_write, __VA_ARGS__)))
       7  
       8  
       9  void f1 (int n, int[n], int);               // { dg-message "designating the bound of variable length array argument 2" "note" }
      10  
      11  // Verify that a redundant attribute access doesn't trigger a warning.
      12  RW (2, 1) void f1 (int n, int[n], int);
      13  
      14  RW (2, 3) void f1 (int n, int[n], int);     // { dg-warning "attribute 'access\\\(read_write, 2, 3\\\)' positional argument 2 conflicts with previous designation by argument 1" }
      15  
      16  
      17  /* Verify that applying the attribute to a VLA with an unspecified bound
      18     doesn't trigger any warnings, both with and without a size operand.  */
      19            void f2 (int, int[*], int);
      20  RW (2)    void f2 (int, int[*], int);
      21  RW (2, 3) void f2 (int, int[*], int);
      22  
      23  /* Designating a parameter that comes before the VLA is the same as
      24     using the standard VLA int[n] syntax.  It might be worth issuing
      25     a portability warning suggesting to prefer the standard syntax.  */
      26            void f3 (int, int[*], int);
      27  RW (2, 1) void f3 (int, int[*], int);
      28  
      29  /* Designating a parameter that comes after the VLA cannot be expressed
      30     using the standard VLA int[n] syntax.  Verify it doesn't trigger
      31     a warning.  */
      32            void f4 (int, int[*], int);
      33  RW (2, 3) void f4 (int, int[*], int);
      34  
      35  /* Also verify the same on the same declaration.  */
      36            void f5 (int[*], int) RW (1, 2);
      37  RW (1, 2) void f5 (int[*], int);
      38  RW (1, 2) void f5 (int[*], int) RW (1, 2);
      39  
      40  
      41  /* Verify that designating a VLA parameter with an explicit bound without
      42     also designating the same bound parameter triggers a warning (it has
      43     a different meaning).  */
      44         void f7 (int n, int[n]);         // { dg-message "21:note: designating the bound of variable length array argument 2" "note" }
      45  RW (2) void f7 (int n, int[n]);         // { dg-warning "attribute 'access\\\(read_write, 2\\\)' missing positional argument 2 provided in previous designation by argument 1" }
      46  
      47            void f8 (int n, int[n]);
      48  RW (2, 1) void f8 (int n, int[n]);
      49  
      50  
      51            void f9 (int, char[]);        // { dg-message "25:note: previously declared as an ordinary array 'char\\\[]'" note" }
      52  RW (2)    void f9 (int n, char a[n])    // { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array" }
      53                                          // { dg-warning "attribute 'access *\\\(read_write, 2\\\)' positional argument 2 missing in previous designation" "" { target *-*-* } .-1 }
      54                                          // { dg-message "24:note: designating the bound of variable length array argument 2" "note" { target *-*-* } .-2 }
      55  { (void)&n; (void)&a; }
      56  
      57  
      58            void f10 (int, char[]);       // { dg-message "26:note: previously declared as an ordinary array 'char\\\[]'" "note" }
      59  RW (2, 1) void f10 (int n, char a[n])   // { dg-warning "attribute 'access *\\\(read_write, 2, 1\\\)' positional argument 2 missing in previous designation" "pr????" { xfail *-*-* } }
      60                                          // { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array"  "" { target *-*-* } .-1 }
      61  { (void)&n; (void)&a; }
      62  
      63  
      64  /* The following is diagnosed to point out declarations with the T[*]
      65     form in headers where specifying the bound is just as important as
      66     in the definition (to detect bugs).  */
      67            void f11 (int, char[*]);      // { dg-warning "argument 2 of type 'char\\\[\\\*\\\]' declared with 1 unspecified variable bound" }
      68            void f11 (int m, char a[m]);  // { dg-message "subsequently declared as 'char\\\[m]' with 0 unspecified variable bounds" "note" }
      69  RW (2, 1) void f11 (int n, char arr[n]) // { dg-message "subsequently declared as 'char\\\[n]' with 0 unspecified variable bounds" "note" }
      70  { (void)&n; (void)&arr; }
      71  
      72  
      73  /* Verify that redeclaring a function with attribute access applying
      74     to an array parameter of any form is not diagnosed.  */
      75            void f12__ (int, int[]) RW (2, 1);
      76  RW (2, 1) void f12__ (int, int[]);
      77  
      78            void f12_3 (int, int[3]) RW (2, 1);
      79  RW (2, 1) void f12_3 (int, int[3]);
      80  
      81            void f12_n (int n, int[n]) RW (2, 1);
      82  RW (2, 1) void f12_n (int n, int[n]);
      83  
      84            void f12_x (int, int[*]) RW (2, 1);
      85  RW (2, 1) void f12_x (int, int[*]);
      86  
      87            void f13__ (int, int[]);
      88  RW (2, 1) void f13__ (int, int[]);
      89  
      90            void f13_5 (int, int[5]);
      91  RW (2, 1) void f13_5 (int, int[5]);
      92  
      93            void f13_n (int n, int[n]);
      94  RW (2, 1) void f13_n (int n, int[n]);
      95  
      96            void f13_x (int, int[*]);
      97  RW (2, 1) void f13_x (int, int[*]);
      98  
      99  RW (2, 1) void f14__ (int, int[]);
     100            void f14__ (int, int[]);
     101  
     102  RW (2, 1) void f14_7 (int, int[7]);
     103            void f14_7 (int, int[7]);
     104  
     105  RW (2, 1) void f14_n (int n, int[n]);
     106            void f14_n (int n, int[n]);
     107  
     108  RW (2, 1) void f14_x (int, int[*]);
     109            void f14_x (int, int[*]);
     110  
     111  typedef void G1 (int n, int[n], int);
     112  
     113  G1 g1;
     114  
     115  /* The warning is about the attribute positional argument 2 which refers
     116     to the last function argument.  Ideally, the caret would be under
     117     the corresponding function argument, i.e., the last one here) but
     118     that location isn't available yet.  Verify that the caret doesn't
     119     point to function argument 1 which is the VLA bound (that's what
     120     the caret in the note points to).  */
     121  RW (2, 3) void g1 (int n, int[n], int);     // { dg-warning "16: attribute 'access *\\\(read_write, 2, 3\\\)' positional argument 2 conflicts with previous designation by argument 3" }
     122  // { dg-message "24:designating the bound of variable length array argument 2" "note" { target *-*-* } .-1 }