[llvm-bugs] [Bug 40602] New: clang allows static VLAs for C99

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 5 04:10:33 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40602

            Bug ID: 40602
           Summary: clang allows static VLAs for C99
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: henric.karlsson at ericsson.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Created attachment 21434
  --> https://bugs.llvm.org/attachment.cgi?id=21434&action=edit
example code

It seems like clang is at least not consistent with how VLAs are allowed, and I
think clang is a bit too permissive. A VLA should not be allowed as static
variable.
reproducer command:
clang -S -std=c99 vla_tst.c

Code below is the same as in attached file vla_tst.c
Consider the following:

const int xx = 1;

- gcc gives an error for arrx, and global VLAs sounds strange, but clang
accepts this, possibly because xx is known at compiletime? But is not a
"constant expression" so should still be a VLA.
int arrx[xx]; 

- here clang gives an error for arr2 but not arr1. gcc gives an error for the
garr typedef (and arr2).
typedef int garr[xx];
void fn0() {
  typedef int larr[xx];
  static garr arr1;
  static larr arr2;
}


- clang accepts arr3, but a static storage should not be allowed for a VLA.
void fn1() {
  const int a = 1;
  static int arr3[a];
}

- Here arr4 correctly results in an error with clang. So a little confusing why
clang allows some cases but not all.
void fn2() {
  const int a = 1;
  typedef int at[a];
  static at arr4;
}


With -Wpedantic you get warnings for these (from C++ extension? )

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190205/58063d57/attachment.html>


More information about the llvm-bugs mailing list