Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CodeGen] Adds union padding #1289

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed bug, fixed some of the tests
  • Loading branch information
gitoleg committed Jan 29, 2025
commit 59954bb37728dafe2a80e6e397c8e7200eb5fecc
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ CIRRecordLowering::CIRRecordLowering(CIRGenTypes &cirGenTypes,
astRecordLayout{cirGenTypes.getContext().getASTRecordLayout(recordDecl)},
dataLayout{cirGenTypes.getModule().getModule()},
IsZeroInitializable(true), IsZeroInitializableAsBase(true),
isPacked{isPacked} {}
isPacked{isPacked}, isPadded{false} {}

void CIRRecordLowering::setBitFieldInfo(const FieldDecl *FD,
CharUnits StartOffset,
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/agg-init2.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// CHECK: !ty_Zero = !cir.struct<struct "Zero" {!u8i}>
// CHECK: !ty_Zero = !cir.struct<struct "Zero" padded {!u8i}>

struct Zero {
void yolo();
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/call-via-class-member-funcptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class f {
const char *f::b() { return g.b(h); }
void fn1() { f f1; }

// CIR: ty_a = !cir.struct<class "a" {!u8i} #cir.record.decl.ast>
// CIR: ty_a = !cir.struct<class "a" padded {!u8i} #cir.record.decl.ast>
// CIR: ty_f = !cir.struct<class "f" {!ty_a}>

// CIR: cir.global external @h = #cir.int<0>
Expand Down
8 changes: 4 additions & 4 deletions clang/test/CIR/CodeGen/conditional-cleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace test7 {
}
}

// CIR-DAG: ![[A:.*]] = !cir.struct<struct "test7::A" {!u8i}
// CIR-DAG: ![[B:.*]] = !cir.struct<struct "test7::B" {!u8i}
// CIR-DAG: ![[A:.*]] = !cir.struct<struct "test7::A" padded {!u8i}
// CIR-DAG: ![[B:.*]] = !cir.struct<struct "test7::B" padded {!u8i}

// CIR_EH-DAG: ![[A:.*]] = !cir.struct<struct "test7::A" {!u8i}
// CIR_EH-DAG: ![[B:.*]] = !cir.struct<struct "test7::B" {!u8i}
// CIR_EH-DAG: ![[A:.*]] = !cir.struct<struct "test7::A" padded {!u8i}
// CIR_EH-DAG: ![[B:.*]] = !cir.struct<struct "test7::B" padded {!u8i}

// CIR-LABEL: _ZN5test74testEv
// CIR: %[[RET_VAL:.*]] = cir.alloca !cir.ptr<![[B]]>, !cir.ptr<!cir.ptr<![[B]]>>, ["__retval"] {alignment = 8 : i64}
Expand Down
14 changes: 7 additions & 7 deletions clang/test/CIR/CodeGen/coro-task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ co_invoke_fn co_invoke;

}} // namespace folly::coro

// CHECK-DAG: ![[IntTask:.*]] = !cir.struct<struct "folly::coro::Task<int>" {!u8i}>
// CHECK-DAG: ![[VoidTask:.*]] = !cir.struct<struct "folly::coro::Task<void>" {!u8i}>
// CHECK-DAG: ![[VoidPromisse:.*]] = !cir.struct<struct "folly::coro::Task<void>::promise_type" {!u8i}>
// CHECK-DAG: ![[CoroHandleVoid:.*]] = !cir.struct<struct "std::coroutine_handle<void>" {!u8i}>
// CHECK-DAG: ![[CoroHandlePromise:ty_.*]] = !cir.struct<struct "std::coroutine_handle<folly::coro::Task<void>::promise_type>" {!u8i}>
// CHECK-DAG: ![[StdString:.*]] = !cir.struct<struct "std::string" {!u8i}>
// CHECK-DAG: ![[SuspendAlways:.*]] = !cir.struct<struct "std::suspend_always" {!u8i}>
// CHECK-DAG: ![[IntTask:.*]] = !cir.struct<struct "folly::coro::Task<int>" padded {!u8i}>
// CHECK-DAG: ![[VoidTask:.*]] = !cir.struct<struct "folly::coro::Task<void>" padded {!u8i}>
// CHECK-DAG: ![[VoidPromisse:.*]] = !cir.struct<struct "folly::coro::Task<void>::promise_type" padded {!u8i}>
// CHECK-DAG: ![[CoroHandleVoid:.*]] = !cir.struct<struct "std::coroutine_handle<void>" padded {!u8i}>
// CHECK-DAG: ![[CoroHandlePromise:ty_.*]] = !cir.struct<struct "std::coroutine_handle<folly::coro::Task<void>::promise_type>" padded {!u8i}>
// CHECK-DAG: ![[StdString:.*]] = !cir.struct<struct "std::string" padded {!u8i}>
// CHECK-DAG: ![[SuspendAlways:.*]] = !cir.struct<struct "std::suspend_always" padded {!u8i}>

// CHECK: module {{.*}} {
// CHECK-NEXT: cir.global external @_ZN5folly4coro9co_invokeE = #cir.zero : !ty_folly3A3Acoro3A3Aco_invoke_fn
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/global-new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
struct e { e(int); };
e *g = new e(0);

// CIR_BEFORE: ![[ty:.*]] = !cir.struct<struct "e" {!u8i}
// CIR_BEFORE: ![[ty:.*]] = !cir.struct<struct "e" padded {!u8i}

// CIR_BEFORE: cir.global external @g = ctor : !cir.ptr<![[ty]]> {
// CIR_BEFORE: %[[GlobalAddr:.*]] = cir.get_global @g : !cir.ptr<!cir.ptr<![[ty]]>>
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/lambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void fn() {
}

// CHECK-DAG: !ty_A = !cir.struct<struct "A" {!s32i}>
// CHECK: !ty_anon2E0_ = !cir.struct<class "anon.0" {!u8i}>
// CHECK: !ty_anon2E0_ = !cir.struct<class "anon.0" padded {!u8i}>
// CHECK-DAG: !ty_anon2E7_ = !cir.struct<class "anon.7" {!ty_A}>
// CHECK-DAG: !ty_anon2E8_ = !cir.struct<class "anon.8" {!cir.ptr<!ty_A>}>
// CHECK-DAG: module
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct string {

} // std namespace

// CHECK: ![[StdString:ty_.*]] = !cir.struct<struct "std::string" {!u8i}>
// CHECK: ![[StdString:ty_.*]] = !cir.struct<struct "std::string" padded {!u8i}>

std::string getstr();
void emplace(std::string &&s);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/new-null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void *operator new[](size_t, void*, bool) throw();

namespace test15 {
struct A { A(); ~A(); };
// CIR-DAG: ![[TEST15A:.*]] = !cir.struct<struct "test15::A" {!u8i}
// CIR-DAG: ![[TEST15A:.*]] = !cir.struct<struct "test15::A" padded {!u8i}

void test0a(void *p) {
new (p) A();
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/packed-structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ typedef struct {


// CIR: !ty_A = !cir.struct<struct "A" packed {!s32i, !s8i}>
// CIR: !ty_C = !cir.struct<struct "C" packed {!s32i, !s8i, !u8i}>
// CIR: !ty_D = !cir.struct<struct "D" packed {!s8i, !u8i, !s32i}
// CIR: !ty_C = !cir.struct<struct "C" packed padded {!s32i, !s8i, !u8i}>
// CIR: !ty_D = !cir.struct<struct "D" packed padded {!s8i, !u8i, !s32i}
// CIR: !ty_F = !cir.struct<struct "F" packed {!s64i, !s8i}
// CIR: !ty_E = !cir.struct<struct "E" packed {!ty_D
// CIR: !ty_G = !cir.struct<struct "G" {!ty_F
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/paren-list-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ struct S1 {
Vec v;
};

// CIR-DAG: ![[VecType:.*]] = !cir.struct<struct "Vec" {!u8i}>
// CIR-DAG: ![[VecType:.*]] = !cir.struct<struct "Vec" padded {!u8i}>
// CIR-DAG: ![[S1:.*]] = !cir.struct<struct "S1" {![[VecType]]}>

// CIR_EH-DAG: ![[VecType:.*]] = !cir.struct<struct "Vec" {!u8i}>
// CIR_EH-DAG: ![[VecType:.*]] = !cir.struct<struct "Vec" padded {!u8i}>
// CIR_EH-DAG: ![[S1:.*]] = !cir.struct<struct "S1" {![[VecType]]}>

template <int I>
Expand Down
10 changes: 7 additions & 3 deletions clang/test/CIR/CodeGen/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ void shouldConstInitStructs(void) {
// CHECK: cir.func @shouldConstInitStructs
struct Foo f = {1, 2, {3, 4}};
// CHECK: %[[#V0:]] = cir.alloca !ty_Foo, !cir.ptr<!ty_Foo>, ["f"] {alignment = 4 : i64}
// CHECK: %[[#V1:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_Foo>), !cir.ptr<!ty_anon_struct> l
// CHECK: %[[#V2:]] = cir.const #cir.const_struct<{#cir.int<1> : !s32i, #cir.int<2> : !s8i, #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>, #cir.const_struct<{#cir.int<3> : !s32i, #cir.int<4> : !s8i}> : !ty_Bar}> : !ty_anon_struct
// CHECK: cir.store %[[#V2]], %[[#V1]] : !ty_anon_struct, !cir.ptr<!ty_anon_struct>
// CHECK: %[[#V1:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_Foo>), !cir.ptr<!ty_anon_struct1>
// CHECK: %[[#V2:]] = cir.const #cir.const_struct<{#cir.int<1> : !s32i, #cir.int<2> : !s8i,
// CHECK-SAME: #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>,
// CHECK-SAME: #cir.const_struct<{#cir.int<3> : !s32i, #cir.int<4> : !s8i,
// CHECK-SAME: #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>}>
// CHECK-SAME: : !ty_anon_struct}> : !ty_anon_struct1
// CHECK: cir.store %[[#V2]], %[[#V1]] : !ty_anon_struct1, !cir.ptr<!ty_anon_struct1>
}

// Should zero-initialize uninitialized global structs.
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/try-catch-dtors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ void yo() {
}
}

// CIR-DAG: ![[VecTy:.*]] = !cir.struct<struct "Vec" {!u8i}>
// CIR-DAG: ![[VecTy:.*]] = !cir.struct<struct "Vec" padded {!u8i}>
// CIR-DAG: ![[S1:.*]] = !cir.struct<struct "S1" {![[VecTy]]}>

// CIR_FLAT-DAG: ![[VecTy:.*]] = !cir.struct<struct "Vec" {!u8i}>
// CIR_FLAT-DAG: ![[VecTy:.*]] = !cir.struct<struct "Vec" padded {!u8i}>
// CIR_FLAT-DAG: ![[S1:.*]] = !cir.struct<struct "S1" {![[VecTy]]}>

// CIR: cir.scope {
Expand Down