[all-commits] [llvm/llvm-project] 886715: [clang] Introduce -fstrict-flex-arrays=<n> for str...

serge-sans-paille via All-commits all-commits at lists.llvm.org
Fri Jun 24 07:14:13 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 886715af962de2c92fac4bd37104450345711e4a
  Author: serge-sans-paille <sguelton at redhat.com>
  Date:   2022-06-24 (Fri, 24 Jun 2022)

  Changed paths:
    M clang/docs/ClangCommandLineReference.rst
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/AST/Expr.h
    M clang/include/clang/Basic/LangOptions.def
    M clang/include/clang/Driver/Options.td
    M clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
    M clang/lib/AST/Expr.cpp
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/lib/Sema/SemaChecking.cpp
    M clang/lib/StaticAnalyzer/Core/MemRegion.cpp
    M clang/test/CodeGen/bounds-checking.c
    A clang/test/CodeGen/object-size-flex-array.c
    M clang/test/CodeGenObjC/ubsan-array-bounds.m
    M clang/test/Sema/array-bounds-ptr-arith.c
    A clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp

  Log Message:
  [clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible arrays

Some code [0] consider that trailing arrays are flexible, whatever their size.
Support for these legacy code has been introduced in
f8f632498307d22e10fab0704548b270b15f1e1e but it prevents evaluation of
__builtin_object_size and __builtin_dynamic_object_size in some legit cases.

Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is

n = 0: current behavior, any trailing array member is a flexible array. The default.
n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member
n = 2: any trailing array member of undefined or 0 size is a flexible array member
n = 3: any trailing array member of undefined size is a flexible array member (strict c99 conformance)

Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836

[0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions

More information about the All-commits mailing list