[clang] [clang][bytecode] Fix tail padding with __builtin_object_size (PR #209771)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 07:26:48 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/209771
This fixes the new libcxx/atomics/builtin_clear_padding.pass.cpp
>From 136b4c2660df42e9feec21c071acf3c976607822 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 15 Jul 2026 16:24:00 +0200
Subject: [PATCH] [clang][bytecode] Fix tail padding with __builtin_object_size
This fixes the new libcxx/atomics/builtin_clear_padding.pass.cpp
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 6 ++----
clang/test/AST/ByteCode/builtin-object-size.cpp | 8 ++++++++
2 files changed, 10 insertions(+), 4 deletions(-)
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);
+ }
+}
More information about the cfe-commits
mailing list