================ @@ -0,0 +1,60 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wno-missing-declarations \ +// RUN: -emit-llvm -o - %s | FileCheck %s + +// See https://github.com/llvm/llvm-project/issues/200014 +// +// __builtin_dynamic_object_size on a flexible array member must consult the +// 'counted_by' attribute, even when the containing struct is accessed +// directly (local or global variable) rather than through a pointer +// dereference. Previously the AST constant evaluator would fold the call to +// a layout-derived size (trailing padding for locals; trailing initializer +// data for globals), bypassing the runtime counted_by path in CGBuiltin. + +typedef __SIZE_TYPE__ size_t; + +struct annotated_flex { + size_t count; + char induce_padding; + char fam[] __attribute__((counted_by(count))); +}; + +struct annotated_flex gaf = { + .fam = "i am very long", + .count = 10, +}; + +extern size_t sink; + +// Global access: must consult gaf.count at runtime; the size must not be +// folded to the static initializer length (15). +// +// CHECK-LABEL: define dso_local {{.*}}i64 @test_global() +// CHECK: load i64, ptr @gaf +// CHECK-NOT: ret i64 15 ---------------- kees wrote:
I always forget about `update_cc_test_checks.py`. I will get the tests improved. https://github.com/llvm/llvm-project/pull/201161 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
