Skip to content

Commit de67383

Browse files
committed
IP
1 parent 899c2be commit de67383

File tree

17 files changed

+171
-22
lines changed

17 files changed

+171
-22
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,11 +2406,11 @@ class ASTContext : public RefCountedBase<ASTContext> {
24062406

24072407
/// Return the alignment in bits that should be given to a
24082408
/// global variable with type \p T.
2409-
unsigned getAlignOfGlobalVar(QualType T) const;
2409+
unsigned getAlignOfGlobalVar(QualType T, bool HasDef) const;
24102410

24112411
/// Return the alignment in characters that should be given to a
24122412
/// global variable with type \p T.
2413-
CharUnits getAlignOfGlobalVarInChars(QualType T) const;
2413+
CharUnits getAlignOfGlobalVarInChars(QualType T, bool HasDef) const;
24142414

24152415
/// Return a conservative estimate of the alignment of the specified
24162416
/// decl \p D.

clang/include/clang/Basic/TargetInfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,11 @@ class TargetInfo : public TransferrableTargetInfo,
704704
}
705705

706706
/// getMinGlobalAlign - Return the minimum alignment of a global variable,
707-
/// unless its alignment is explicitly reduced via attributes.
708-
virtual unsigned getMinGlobalAlign (uint64_t) const {
707+
/// unless its alignment is explicitly reduced via attributes. It may be
708+
/// that an external symbol needs to be considered unaligned (like
709+
/// artificial symbols created from a linker script). If \param HasDef is
710+
/// false, this symbol does not have a definition and is external.
711+
virtual unsigned getMinGlobalAlign(uint64_t Size, bool HasDef) const {
709712
return MinGlobalAlign;
710713
}
711714

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4587,6 +4587,10 @@ def munaligned_access : Flag<["-"], "munaligned-access">, Group<m_Group>,
45874587
HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64/LoongArch/RISC-V only)">;
45884588
def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group<m_Group>,
45894589
HelpText<"Force all memory accesses to be aligned (AArch32/AArch64/LoongArch/RISC-V only)">;
4590+
def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group<m_Group>,
4591+
HelpText<"Expect external char-aligned symbols to be without ABI alignment (SystemZ only)">;
4592+
def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, Group<m_Group>,
4593+
HelpText<"Expect external char-aligned symbols to be without ABI alignment (SystemZ only)">;
45904594
} // let Flags = [TargetSpecific]
45914595
def mstrict_align : Flag<["-"], "mstrict-align">, Alias<mno_unaligned_access>,
45924596
Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,8 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
16811681
if (VD->hasGlobalStorage() && !ForAlignof) {
16821682
uint64_t TypeSize =
16831683
!BaseT->isIncompleteType() ? getTypeSize(T.getTypePtr()) : 0;
1684-
Align = std::max(Align, getTargetInfo().getMinGlobalAlign(TypeSize));
1684+
Align = std::max(Align, getTargetInfo().getMinGlobalAlign(
1685+
TypeSize, VD->hasDefinition()));
16851686
}
16861687

16871688
// Fields can be subject to extra alignment constraints, like if
@@ -2502,17 +2503,19 @@ unsigned ASTContext::getTargetDefaultAlignForAttributeAligned() const {
25022503
}
25032504

25042505
/// getAlignOfGlobalVar - Return the alignment in bits that should be given
2505-
/// to a global variable of the specified type.
2506-
unsigned ASTContext::getAlignOfGlobalVar(QualType T) const {
2506+
/// to a global variable of the specified type (see comment for
2507+
/// getMinGlobalAlign about HasDef).
2508+
unsigned ASTContext::getAlignOfGlobalVar(QualType T, bool HasDef) const {
25072509
uint64_t TypeSize = getTypeSize(T.getTypePtr());
25082510
return std::max(getPreferredTypeAlign(T),
2509-
getTargetInfo().getMinGlobalAlign(TypeSize));
2511+
getTargetInfo().getMinGlobalAlign(TypeSize, HasDef));
25102512
}
25112513

25122514
/// getAlignOfGlobalVarInChars - Return the alignment in characters that
25132515
/// should be given to a global variable of the specified type.
2514-
CharUnits ASTContext::getAlignOfGlobalVarInChars(QualType T) const {
2515-
return toCharUnitsFromBits(getAlignOfGlobalVar(T));
2516+
CharUnits ASTContext::getAlignOfGlobalVarInChars(QualType T,
2517+
bool HasDef) const {
2518+
return toCharUnitsFromBits(getAlignOfGlobalVar(T, HasDef));
25162519
}
25172520

25182521
CharUnits ASTContext::getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const {

clang/lib/Basic/Targets/AArch64.cpp

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

1520-
unsigned MicrosoftARM64TargetInfo::getMinGlobalAlign(uint64_t TypeSize) const {
1521-
unsigned Align = WindowsARM64TargetInfo::getMinGlobalAlign(TypeSize);
1520+
unsigned MicrosoftARM64TargetInfo::getMinGlobalAlign(uint64_t TypeSize,
1521+
bool HasDef) const {
1522+
unsigned Align = WindowsARM64TargetInfo::getMinGlobalAlign(TypeSize, HasDef);
15221523

15231524
// MSVC does size based alignment for arm64 based on alignment section in
15241525
// 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
@@ -236,7 +236,7 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
236236
TargetInfo::CallingConvKind
237237
getCallingConvKind(bool ClangABICompat4) const override;
238238

239-
unsigned getMinGlobalAlign(uint64_t TypeSize) const override;
239+
unsigned getMinGlobalAlign(uint64_t TypeSize, bool HasDef) const override;
240240
};
241241

242242
// ARM64 MinGW target

clang/lib/Basic/Targets/CSKY.cpp

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

311-
unsigned CSKYTargetInfo::getMinGlobalAlign(uint64_t Size) const {
311+
unsigned CSKYTargetInfo::getMinGlobalAlign(uint64_t Size, bool HasDef) const {
312312
if (Size >= 32)
313313
return 32;
314314
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 override;
74+
unsigned getMinGlobalAlign(uint64_t, bool) const override;
7575

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

clang/lib/Basic/Targets/NVPTX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
115115
LongAlign = HostTarget->getLongAlign();
116116
LongLongWidth = HostTarget->getLongLongWidth();
117117
LongLongAlign = HostTarget->getLongLongAlign();
118-
MinGlobalAlign = HostTarget->getMinGlobalAlign(/* TypeSize = */ 0);
118+
MinGlobalAlign = HostTarget->getMinGlobalAlign(/* TypeSize = */ 0,
119+
/* HasDef = */ true);
119120
NewAlign = HostTarget->getNewAlign();
120121
DefaultAlignForAttributeAligned =
121122
HostTarget->getDefaultAlignForAttributeAligned();

clang/lib/Basic/Targets/SPIR.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public TargetInfo {
124124
LongAlign = HostTarget->getLongAlign();
125125
LongLongWidth = HostTarget->getLongLongWidth();
126126
LongLongAlign = HostTarget->getLongLongAlign();
127-
MinGlobalAlign = HostTarget->getMinGlobalAlign(/* TypeSize = */ 0);
127+
MinGlobalAlign = HostTarget->getMinGlobalAlign(/* TypeSize = */ 0,
128+
/* HasDef = */ true);
128129
NewAlign = HostTarget->getNewAlign();
129130
DefaultAlignForAttributeAligned =
130131
HostTarget->getDefaultAlignForAttributeAligned();

0 commit comments

Comments
 (0)