This is an archive of the discontinued LLVM Phabricator instance.

[clang] -fsanitize=array-bounds: treat all trailing size-1 arrays as flexible
AbandonedPublic

Authored by sberg on Jun 27 2022, 7:06 AM.

Details

Summary

...even if the size resulted from a macro expansion. This reverts back to the behavior prior to
https://github.com/llvm/llvm-project/commit/886715af962de2c92fac4bd37104450345711e4a "[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible arrays". The new behavior caused false out-of-bounds-index reports from e.g. HarfBuzz built with -fsanitize=array-bounds: HarfBuzz has various "fake" flexible array members of the form

Type                arrayZ[HB_VAR_ARRAY];

in https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-open-type.hh, where HB_VAR_ARRAY is defined as

#ifndef HB_VAR_ARRAY
#define HB_VAR_ARRAY 1
#endif

in https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-machinery.hh.

Also added a test.

Diff Detail

Event Timeline

sberg created this revision.Jun 27 2022, 7:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2022, 7:06 AM
sberg requested review of this revision.Jun 27 2022, 7:06 AM
clang/include/clang/AST/Expr.h
455

Maybe default to false here?

clang/test/CodeGen/bounds-checking.c
69

The above checks look for CHECK-NOT: call {{.*}} @llvm.{{(ubsan)?trap}}

sberg abandoned this revision.Jun 27 2022, 11:02 PM

I'm abandoning this as the underlying https://reviews.llvm.org/D126864 "[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible arrays" has been reverted for now.

I documented all my issues with that underlying commit (including, but not limited to what was presented here) in my comment at https://reviews.llvm.org/D126864#3614235.