[PATCH] D134902: [clang] Implement -fstrict-flex-arrays=3

Bill Wendling via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 10 16:35:08 PDT 2022


void added a reviewer: rsmith.
void added a subscriber: rsmith.
void added a comment.

@rsmith, @serge-sans-paille, and @kees, I need some advice. There's a test in `clang/test/CodeGen/bounds-checking.c` that's checking bounds stuff on unions. The behavior is...weird to me. It says that an array of 0 or 1 is a FAM, but one larger is not (see below). That seems counter to how structs are handled. If this is true, then the check in `clang/lib/AST/Expr.cpp` also needs to be updated...

  union U { int a[0]; int b[1]; int c[2]; };                                             
    
  // CHECK-LABEL: define {{.*}} @f4                                                      
  int f4(union U *u, int i) {
    // a and b are treated as flexible array members.
    // CHECK-NOT: @llvm.ubsantrap                                                        
    return u->a[i] + u->b[i] + u->c[i];                                                  
    // CHECK: }
  }                                                                                      
    
  // CHECK-LABEL: define {{.*}} @f5
  int f5(union U *u, int i) {
    // c is not a flexible array member.
    // NONLOCAL: call {{.*}} @llvm.ubsantrap                                             
    return u->c[i];
    // CHECK: }                                                                          
  }   


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134902



More information about the cfe-commits mailing list