Skip to content

Commit ba902e5

Browse files
committed
Refactor to avoid link problems
1 parent 5c1c5d4 commit ba902e5

File tree

11 files changed

+35
-20
lines changed

11 files changed

+35
-20
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,13 +2405,19 @@ class ASTContext : public RefCountedBase<ASTContext> {
24052405
unsigned getTargetDefaultAlignForAttributeAligned() const;
24062406

24072407
/// Return the alignment in bits that should be given to a
2408-
/// global variable with type \p T.
2408+
/// global variable with type \p T. If \p VD is non-null it will be
2409+
/// considered specifically for the query.
24092410
unsigned getAlignOfGlobalVar(QualType T, const VarDecl *VD) const;
24102411

24112412
/// Return the alignment in characters that should be given to a
2412-
/// global variable with type \p T.
2413+
/// global variable with type \p T. If \p VD is non-null it will be
2414+
/// considered specifically for the query.
24132415
CharUnits getAlignOfGlobalVarInChars(QualType T, const VarDecl *VD) const;
24142416

2417+
/// Return the minimum alignement as specified by the target. If \p VD is
2418+
/// non-null it may be used to identify external or weak variables.
2419+
unsigned getMinGlobalAlignOfVar(uint64_t Size, const VarDecl *VD) const;
2420+
24152421
/// Return a conservative estimate of the alignment of the specified
24162422
/// decl \p D.
24172423
///

clang/include/clang/Basic/TargetInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class DiagnosticsEngine;
5050
class LangOptions;
5151
class CodeGenOptions;
5252
class MacroBuilder;
53-
class VarDecl;
5453

5554
/// Contains information gathered from parsing the contents of TargetAttr.
5655
struct ParsedTargetAttr {
@@ -705,9 +704,10 @@ class TargetInfo : public TransferrableTargetInfo,
705704
}
706705

707706
/// getMinGlobalAlign - Return the minimum alignment of a global variable,
708-
/// unless its alignment is explicitly reduced via attributes. If \param VD
709-
/// is non-null, it may be used to examine the specific variable's attributes.
710-
virtual unsigned getMinGlobalAlign(uint64_t Size, const VarDecl *VD) const {
707+
/// unless its alignment is explicitly reduced via attributes. If \param
708+
/// HasNonWeakDef is true, this concerns a VarDecl which has a definition
709+
/// in current translation unit and that is not weak.
710+
virtual unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const {
711711
return MinGlobalAlign;
712712
}
713713

clang/lib/AST/ASTContext.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,8 +1688,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
16881688
if (VD->hasGlobalStorage() && !ForAlignof) {
16891689
uint64_t TypeSize =
16901690
!BaseT->isIncompleteType() ? getTypeSize(T.getTypePtr()) : 0;
1691-
Align =
1692-
std::max(Align, getTargetInfo().getMinGlobalAlign(TypeSize, VD));
1691+
Align = std::max(Align, getMinGlobalAlignOfVar(TypeSize, VD));
16931692
}
16941693

16951694
// Fields can be subject to extra alignment constraints, like if
@@ -2514,7 +2513,7 @@ unsigned ASTContext::getTargetDefaultAlignForAttributeAligned() const {
25142513
unsigned ASTContext::getAlignOfGlobalVar(QualType T, const VarDecl *VD) const {
25152514
uint64_t TypeSize = getTypeSize(T.getTypePtr());
25162515
return std::max(getPreferredTypeAlign(T),
2517-
getTargetInfo().getMinGlobalAlign(TypeSize, VD));
2516+
getMinGlobalAlignOfVar(TypeSize, VD));
25182517
}
25192518

25202519
/// getAlignOfGlobalVarInChars - Return the alignment in characters that
@@ -2524,6 +2523,14 @@ CharUnits ASTContext::getAlignOfGlobalVarInChars(QualType T,
25242523
return toCharUnitsFromBits(getAlignOfGlobalVar(T, VD));
25252524
}
25262525

2526+
unsigned ASTContext::getMinGlobalAlignOfVar(uint64_t Size,
2527+
const VarDecl *VD) const {
2528+
// Make the default handling as that of a non-weak definition in the
2529+
// current translation unit.
2530+
bool HasNonWeakDef = !VD || (VD->hasDefinition() && !VD->isWeak());
2531+
return getTargetInfo().getMinGlobalAlign(Size, HasNonWeakDef);
2532+
}
2533+
25272534
CharUnits ASTContext::getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const {
25282535
CharUnits Offset = CharUnits::Zero();
25292536
const ASTRecordLayout *Layout = &getASTRecordLayout(RD);

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,9 @@ MicrosoftARM64TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
15181518
}
15191519

15201520
unsigned MicrosoftARM64TargetInfo::getMinGlobalAlign(uint64_t TypeSize,
1521-
const VarDecl *VD) const {
1522-
unsigned Align = WindowsARM64TargetInfo::getMinGlobalAlign(TypeSize, VD);
1521+
bool HasNonWeakDef) const {
1522+
unsigned Align =
1523+
WindowsARM64TargetInfo::getMinGlobalAlign(TypeSize, HasNonWeakDef);
15231524

15241525
// MSVC does size based alignment for arm64 based on alignment section in
15251526
// below document, replicate that to keep alignment consistent with object

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
237237
getCallingConvKind(bool ClangABICompat4) const override;
238238

239239
unsigned getMinGlobalAlign(uint64_t TypeSize,
240-
const VarDecl *VD) const override;
240+
bool HasNonWeakDef) const override;
241241
};
242242

243243
// ARM64 MinGW target

clang/lib/Basic/Targets/CSKY.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ bool CSKYTargetInfo::validateAsmConstraint(
309309
}
310310

311311
unsigned CSKYTargetInfo::getMinGlobalAlign(uint64_t Size,
312-
const VarDecl *VD) const {
312+
bool HasNonWeakDef) const {
313313
if (Size >= 32)
314314
return 32;
315315
return 0;

clang/lib/Basic/Targets/CSKY.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public TargetInfo {
7171

7272
bool isValidCPUName(StringRef Name) const override;
7373

74-
unsigned getMinGlobalAlign(uint64_t, const VarDecl *) const override;
74+
unsigned getMinGlobalAlign(uint64_t, bool HasNonWeakDef) const override;
7575

7676
ArrayRef<Builtin::Info> getTargetBuiltins() const override;
7777

clang/lib/Basic/Targets/NVPTX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
116116
LongLongWidth = HostTarget->getLongLongWidth();
117117
LongLongAlign = HostTarget->getLongLongAlign();
118118
MinGlobalAlign = HostTarget->getMinGlobalAlign(/* TypeSize = */ 0,
119-
/* VD = */ nullptr);
119+
/* HasNonWeakDef = */ true);
120120
NewAlign = HostTarget->getNewAlign();
121121
DefaultAlignForAttributeAligned =
122122
HostTarget->getDefaultAlignForAttributeAligned();

clang/lib/Basic/Targets/SPIR.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public TargetInfo {
125125
LongAlign = HostTarget->getLongAlign();
126126
LongLongWidth = HostTarget->getLongLongWidth();
127127
LongLongAlign = HostTarget->getLongLongAlign();
128-
MinGlobalAlign = HostTarget->getMinGlobalAlign(/* TypeSize = */ 0,
129-
/* VD = */ nullptr);
128+
MinGlobalAlign =
129+
HostTarget->getMinGlobalAlign(/* TypeSize = */ 0,
130+
/* HasNonWeakDef = */ true);
130131
NewAlign = HostTarget->getNewAlign();
131132
DefaultAlignForAttributeAligned =
132133
HostTarget->getDefaultAlignForAttributeAligned();

clang/lib/Basic/Targets/SystemZ.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ bool SystemZTargetInfo::hasFeature(StringRef Feature) const {
140140
}
141141

142142
unsigned SystemZTargetInfo::getMinGlobalAlign(uint64_t Size,
143-
const VarDecl *VD) const {
143+
bool HasNonWeakDef) const {
144144
// Don't enforce the minimum alignment on an external or weak symbol if
145145
// -munaligned-symbols is passed.
146-
if (UnalignedSymbols && VD && (!VD->hasDefinition() || VD->isWeak()))
146+
if (UnalignedSymbols && !HasNonWeakDef)
147147
return 0;
148148

149149
return MinGlobalAlign;

clang/lib/Basic/Targets/SystemZ.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
6666
HasStrictFP = true;
6767
}
6868

69-
unsigned getMinGlobalAlign(uint64_t Size, const VarDecl *VD) const override;
69+
unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override;
7070

7171
void getTargetDefines(const LangOptions &Opts,
7272
MacroBuilder &Builder) const override;

0 commit comments

Comments
 (0)