File tree Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,14 @@ void CIRGenFunction::emitDecl(const Decl &d) {
276276 case Decl::OpenACCRoutine:
277277 emitOpenACCRoutine (cast<OpenACCRoutineDecl>(d));
278278 return ;
279+ case Decl::Typedef: // typedef int X;
280+ case Decl::TypeAlias: { // using X = int; [C++0x]
281+ QualType ty = cast<TypedefNameDecl>(d).getUnderlyingType ();
282+ assert (!cir::MissingFeatures::generateDebugInfo ());
283+ if (ty->isVariablyModifiedType ())
284+ cgm.errorNYI (d.getSourceRange (), " emitDecl: variably modified type" );
285+ return ;
286+ }
279287 default :
280288 cgm.errorNYI (d.getSourceRange (),
281289 std::string (" emitDecl: unhandled decl type: " ) +
Original file line number Diff line number Diff line change @@ -618,6 +618,8 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
618618 emitGlobalOpenACCDecl (cast<OpenACCDeclareDecl>(decl));
619619 break ;
620620
621+ case Decl::Typedef:
622+ case Decl::TypeAlias: // using foo = bar; [C++11]
621623 case Decl::Record:
622624 case Decl::CXXRecord:
623625 assert (!cir::MissingFeatures::generateDebugInfo ());
Original file line number Diff line number Diff line change @@ -169,3 +169,24 @@ int f6(void) {
169169// OGCG-NEXT: entry:
170170// OGCG-NEXT: %[[GV:.*]] = load i32, ptr @gv, align 4
171171// OGCG-NEXT: ret i32 %[[GV]]
172+
173+ typedef unsigned long size_type ;
174+ typedef unsigned long _Tp ;
175+
176+ size_type max_size (void ) {
177+ return (size_type )~0 / sizeof (_Tp );
178+ }
179+
180+ // CIR: cir.func @max_size()
181+ // CIR: %0 = cir.alloca !u64i, !cir.ptr<!u64i>, ["__retval"] {alignment = 8 : i64}
182+ // CIR: %1 = cir.const #cir.int<0> : !s32i
183+ // CIR: %2 = cir.unary(not, %1) : !s32i, !s32i
184+ // CIR: %3 = cir.cast(integral, %2 : !s32i), !u64i
185+ // CIR: %4 = cir.const #cir.int<8> : !u64i
186+ // CIR: %5 = cir.binop(div, %3, %4) : !u64i
187+
188+ // LLVM: define i64 @max_size()
189+ // LLVM: store i64 2305843009213693951, ptr
190+
191+ // OGCG: define{{.*}} i64 @max_size()
192+ // OGCG: ret i64 2305843009213693951
Original file line number Diff line number Diff line change @@ -87,3 +87,18 @@ int *f5() {
8787// CHECK-NEXT: cir.store %[[P]], %[[RET_ADDR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
8888// CHECK-NEXT: %[[RET_VAL:.*]] = cir.load %[[RET_ADDR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>
8989// CHECK-NEXT: cir.return %[[RET_VAL]] : !cir.ptr<!s32i>
90+
91+ using size_type = unsigned long ;
92+ using _Tp = unsigned long ;
93+
94+ size_type max_size () {
95+ return size_type (~0 ) / sizeof (_Tp);
96+ }
97+
98+ // CHECK: cir.func @max_size()
99+ // CHECK: %0 = cir.alloca !u64i, !cir.ptr<!u64i>, ["__retval"] {alignment = 8 : i64}
100+ // CHECK: %1 = cir.const #cir.int<0> : !s32i
101+ // CHECK: %2 = cir.unary(not, %1) : !s32i, !s32i
102+ // CHECK: %3 = cir.cast(integral, %2 : !s32i), !u64i
103+ // CHECK: %4 = cir.const #cir.int<8> : !u64i
104+ // CHECK: %5 = cir.binop(div, %3, %4) : !u64i
Original file line number Diff line number Diff line change 1+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+ // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+ // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+ // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+ void local_typedef (void ) {
9+ typedef struct {int a ;} Struct ;
10+ Struct s ;
11+ }
12+
13+ // CIR: cir.func @local_typedef()
14+ // CIR: cir.alloca !cir.record<struct "Struct" {!s32i}>,
15+ // CIR-SAME: !cir.ptr<!cir.record<struct "Struct" {!s32i}>>, ["s"]
16+ // CIR-SAME: {alignment = 4 : i64}
17+ // CIR: cir.return
18+
19+ // LLVM: %struct.Struct = type { i32 }
20+ // LLVM: define void @local_typedef()
21+ // LLVM: alloca %struct.Struct, i64 1, align 4
22+ // LLVM: ret void
23+
24+ // OGCG: %struct.Struct = type { i32 }
25+ // OGCG: define{{.*}} void @local_typedef()
26+ // OGCG: alloca %struct.Struct, align 4
27+ // OGCG: ret void
You can’t perform that action at this time.
0 commit comments