[clang] [clang][bytecode] Fix tail padding with __builtin_object_size (PR #209771)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 07:39:17 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This fixes the new libcxx/atomics/builtin_clear_padding.pass.cpp
---
Full diff: https://github.com/llvm/llvm-project/pull/209771.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+2-4)
- (modified) clang/test/AST/ByteCode/builtin-object-size.cpp (+8)
``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 70717720c592d..a539fb26abc08 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2299,11 +2299,9 @@ static bool interp__builtin_memchr(InterpState &S, CodePtr OpPC,
static std::optional<unsigned> computeFullDescSize(const ASTContext &ASTCtx,
const Descriptor *Desc) {
- if (Desc->isPrimitive())
+ if (Desc->isPrimitive() || Desc->isArray())
return ASTCtx.getTypeSizeInChars(Desc->getType()).getQuantity();
- if (Desc->isArray())
- return ASTCtx.getTypeSizeInChars(Desc->getElemQualType()).getQuantity() *
- Desc->getNumElems();
+
if (Desc->isRecord()) {
// Can't use Descriptor::getType() as that may return a pointer type. Look
// at the decl directly.
diff --git a/clang/test/AST/ByteCode/builtin-object-size.cpp b/clang/test/AST/ByteCode/builtin-object-size.cpp
index e4433ea700ccb..295b6b4717740 100644
--- a/clang/test/AST/ByteCode/builtin-object-size.cpp
+++ b/clang/test/AST/ByteCode/builtin-object-size.cpp
@@ -55,3 +55,11 @@ namespace InvalidBase {
constexpr size_t bos_dtor = __builtin_object_size(&(T&)(T&&)invalid_base_2(), 0); // expected-error {{must be initialized by a constant expression}} \
// expected-note {{non-literal type 'T'}}
}
+
+namespace Padding {
+ typedef long double LongDouble3Vec __attribute__((ext_vector_type(3)));
+ void foo() {
+ LongDouble3Vec v1, v2;
+ static_assert(__builtin_object_size(&v1, 0) == 64);
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/209771
More information about the cfe-commits
mailing list