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

Support _BitInt and complex C types #14

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions lib/type/DimetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct FundamentalType {
kVtablePtr = 1 << 8,
kNullptr = 1 << 9,
kUTFChar = 1 << 10,
kComplex = 1 << 11,
kSignedChar = kChar | kSigned,
kUnsignedChar = kChar | kUnsigned,
kSignedInt = kInt | kSigned,
Expand Down
1 change: 1 addition & 0 deletions lib/type/DimetaIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct llvm::yaml::ScalarEnumerationTraits<dimeta::FundamentalType::Encoding> {
io.enumCase(value, "vtable_ptr", dimeta::FundamentalType::Encoding::kVtablePtr);
io.enumCase(value, "nullptr", dimeta::FundamentalType::Encoding::kNullptr);
io.enumCase(value, "utf_char", dimeta::FundamentalType::Encoding::kUTFChar);
io.enumCase(value, "complex", dimeta::FundamentalType::Encoding::kComplex);
}
};

Expand Down
2 changes: 2 additions & 0 deletions lib/type/DimetaParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ inline FundamentalType::Encoding dwarf2encoding(const unsigned di_encoding) {
return FundamentalType::Encoding::kBool;
case DW_ATE_UTF:
return FundamentalType::Encoding::kUTFChar;
case DW_ATE_complex_float:
return FundamentalType::Encoding::kComplex;
default:
return FundamentalType::Encoding::kUnknown;
}
Expand Down
32 changes: 32 additions & 0 deletions test/pass/c/stack_struct_bitint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %c-to-llvm -std=c2x %s | %apply-verifier -yaml 2>&1 | %filecheck %s

// REQUIRES: !legacyllvm

#include <stddef.h>
#include <stdint.h>

struct SpecialBuiltInTypes {
#if __clang_major__ >= 14
_BitInt(8) bitint8_var;
_BitInt(16) bitint16_var;
_BitInt(32) bitint32_var;
#endif
};

void foo() {
struct SpecialBuiltInTypes types;
}

// CHECK: Members:
// CHECK-NEXT: - Name: bitint8_var
// CHECK-NEXT: Builtin: true
// CHECK-NEXT: Type:
// CHECK-NEXT: Fundamental: { Name: _BitInt, Extent: 1, Encoding: signed_int }
// CHECK-NEXT: - Name: bitint16_var
// CHECK-NEXT: Builtin: true
// CHECK-NEXT: Type:
// CHECK-NEXT: Fundamental: { Name: _BitInt, Extent: 2, Encoding: signed_int }
// CHECK-NEXT: - Name: bitint32_var
// CHECK-NEXT: Builtin: true
// CHECK-NEXT: Type:
// CHECK-NEXT: Fundamental: { Name: _BitInt, Extent: 4, Encoding: signed_int }
44 changes: 44 additions & 0 deletions test/pass/c/stack_struct_specials.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// RUN: %c-to-llvm -std=c99 %s | %apply-verifier -yaml 2>&1 | %filecheck %s

#include <complex.h>
#include <stddef.h>
#include <stdint.h>

struct SpecialBuiltInTypes {
_Bool boolean_var; // Boolean type (C99)

// Complex types (from <complex.h>, C99)
float complex float_complex_var; // Single-precision complex
double complex double_complex_var; // Double-precision complex
long double complex long_double_complex_var; // Extended-precision complex

// float _Imaginary float_imaginary_var; // Single-precision imaginary
// double _Imaginary double_imaginary_var; // Double-precision imaginary
// long double _Imaginary long_double_imaginary_var; // Extended-precision imaginary

// _Decimal32 decimal32_var; // 32-bit decimal floating-point
// _Decimal64 decimal64_var; // 64-bit decimal floating-point
// _Decimal128 decimal128_var; // 128-bit decimal floating-point
};

void foo() {
struct SpecialBuiltInTypes types;
}

// CHECK: Members:
// CHECK-NEXT: - Name: boolean_var
// CHECK-NEXT: Builtin: true
// CHECK-NEXT: Type:
// CHECK-NEXT: Fundamental: { Name: {{bool|_Bool}}, Extent: 1, Encoding: bool }
// CHECK-NEXT: - Name: float_complex_var
// CHECK-NEXT: Builtin: true
// CHECK-NEXT: Type:
// CHECK-NEXT: Fundamental: { Name: complex, Extent: 8, Encoding: complex }
// CHECK-NEXT: - Name: double_complex_var
// CHECK-NEXT: Builtin: true
// CHECK-NEXT: Type:
// CHECK-NEXT: Fundamental: { Name: complex, Extent: 16, Encoding: complex }
// CHECK-NEXT: - Name: long_double_complex_var
// CHECK-NEXT: Builtin: true
// CHECK-NEXT: Type:
// CHECK-NEXT: Fundamental: { Name: complex, Extent: 32, Encoding: complex }
Loading