Skip to content

Commit 0a456ff

Browse files
committed
[CIR][clang] Inline variables processing
There is an implementation for inline variables processing at CIR. The LIT test was taken from clang's cxx1z-inline-variables.cpp where the same functionality is tested for Clang Code generation.
1 parent e1fe8e1 commit 0a456ff

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,11 @@ void CIRGenModule::buildGlobal(GlobalDecl GD) {
510510
assert(0 && "OMPDeclareTargetDeclAttr NYI");
511511
}
512512
}
513-
// If this declaration may have caused an inline variable definition
514-
// to change linkage, make sure that it's emitted.
515-
// TODO(cir): probably use GetAddrOfGlobalVar(VD) below?
516-
assert((astCtx.getInlineVariableDefinitionKind(VD) !=
517-
ASTContext::InlineVariableDefinitionKind::Strong) &&
518-
"not implemented");
513+
// If this declaration may have caused an inline variable definition to
514+
// change linkage, make sure that it's emitted.
515+
if (astCtx.getInlineVariableDefinitionKind(VD) ==
516+
ASTContext::InlineVariableDefinitionKind::Strong)
517+
getAddrOfGlobalVar(VD);
519518
return;
520519
}
521520
}

clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ llvm::Align CIRDataLayout::getAlignment(mlir::Type Ty, bool abiOrPref) const {
184184

185185
// Fetch type alignment from MLIR's data layout.
186186
unsigned align = abiOrPref ? layout.getTypeABIAlignment(Ty)
187-
: layout.getTypePreferredAlignment(Ty);
187+
: layout.getTypePreferredAlignment(Ty);
188188
return llvm::Align(align);
189189
}
190190

clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/X86.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ void X86_64ABIInfo::classify(Type Ty, uint64_t OffsetBase, Class &Lo, Class &Hi,
235235
} else if (isa<IntType>(Ty)) {
236236

237237
// FIXME(cir): Clang's BuiltinType::Kind allow comparisons (GT, LT, etc).
238-
// We should implement this in CIR to simplify the conditions below. Hence,
239-
// Comparisons below might not be truly equivalent to the ones in Clang.
238+
// We should implement this in CIR to simplify the conditions below.
239+
// Hence, Comparisons below might not be truly equivalent to the ones in
240+
// Clang.
240241
if (isa<IntType>(Ty)) {
241242
Current = Class::Integer;
242243
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
// For compatibility with C++11 and C++14, an out-of-line declaration of a
5+
// static constexpr local variable promotes the variable to weak_odr.
6+
struct compat {
7+
static constexpr int a = 1;
8+
static constexpr int b = 2;
9+
static constexpr int c = 3;
10+
static inline constexpr int d = 4;
11+
static const int e = 5;
12+
static const int f = 6;
13+
static const int g = 7;
14+
};
15+
const int &compat_use_before_redecl = compat::b;
16+
const int compat::a;
17+
const int compat::b;
18+
const int compat::c;
19+
const int compat::d;
20+
const int compat::e;
21+
constexpr int compat::f;
22+
constexpr inline int compat::g;
23+
const int &compat_use_after_redecl1 = compat::c;
24+
const int &compat_use_after_redecl2 = compat::d;
25+
const int &compat_use_after_redecl3 = compat::g;
26+
27+
// CHECK: cir.global weak_odr @_ZN6compat1bE = #cir.int<2> : !s32i loc(#loc23)
28+
// CHECK: cir.global weak_odr @_ZN6compat1aE = #cir.int<1> : !s32i loc(#loc25)
29+
// CHECK: cir.global weak_odr @_ZN6compat1cE = #cir.int<3> : !s32i loc(#loc26)
30+
// CHECK: cir.global external @_ZN6compat1eE = #cir.int<5> : !s32i loc(#loc27)
31+
// CHECK: cir.global weak_odr @_ZN6compat1fE = #cir.int<6> : !s32i loc(#loc28)
32+
// CHECK: cir.global linkonce_odr @_ZN6compat1dE = #cir.int<4> : !s32i loc(#loc30)
33+
// CHECK: cir.global linkonce_odr @_ZN6compat1gE = #cir.int<7> : !s32i loc(#loc32)
34+

0 commit comments

Comments
 (0)