Skip to content

Commit fbace0c

Browse files
AutomergerAutomerger
authored andcommitted
Propagating prior merge from 'llvm.org/master'.
apple-llvm-split-commit: 62a824cdf636eeda4f1e7f96f18545541123a4f3 apple-llvm-split-dir: clang/
2 parents 5b4a61e + af22e07 commit fbace0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3321
-192
lines changed

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ BUILTIN(__builtin_amdgcn_s_barrier, "v", "n")
4545
BUILTIN(__builtin_amdgcn_wave_barrier, "v", "n")
4646
BUILTIN(__builtin_amdgcn_s_dcache_inv, "v", "n")
4747
BUILTIN(__builtin_amdgcn_buffer_wbinvl1, "v", "n")
48+
BUILTIN(__builtin_amdgcn_ds_gws_init, "vUiUi", "n")
49+
BUILTIN(__builtin_amdgcn_ds_gws_barrier, "vUiUi", "n")
4850

4951
// FIXME: Need to disallow constant address space.
5052
BUILTIN(__builtin_amdgcn_div_scale, "dddbb*", "n")

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4742,14 +4742,18 @@ def warn_missing_prototype : Warning<
47424742
"no previous prototype for function %0">,
47434743
InGroup<DiagGroup<"missing-prototypes">>, DefaultIgnore;
47444744
def note_declaration_not_a_prototype : Note<
4745-
"this declaration is not a prototype; add 'void' to make it a prototype for a zero-parameter function">;
4745+
"this declaration is not a prototype; add %select{'void'|parameter declarations}0 "
4746+
"to make it %select{a prototype for a zero-parameter function|one}0">;
47464747
def warn_strict_prototypes : Warning<
47474748
"this %select{function declaration is not|block declaration is not|"
47484749
"old-style function definition is not preceded by}0 a prototype">,
47494750
InGroup<DiagGroup<"strict-prototypes">>, DefaultIgnore;
47504751
def warn_missing_variable_declarations : Warning<
47514752
"no previous extern declaration for non-static variable %0">,
47524753
InGroup<DiagGroup<"missing-variable-declarations">>, DefaultIgnore;
4754+
def note_static_for_internal_linkage : Note<
4755+
"declare 'static' if the %select{variable|function}0 is not intended to be "
4756+
"used outside of this translation unit">;
47534757
def err_static_data_member_reinitialization :
47544758
Error<"static data member %0 already has an initializer">;
47554759
def err_redefinition : Error<"redefinition of %0">;

clang/include/clang/Tooling/Syntax/Tokens.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ class TokenBuffer {
200200
llvm::Optional<llvm::ArrayRef<syntax::Token>>
201201
spelledForExpanded(llvm::ArrayRef<syntax::Token> Expanded) const;
202202

203+
/// An expansion produced by the preprocessor, includes macro expansions and
204+
/// preprocessor directives. Preprocessor always maps a non-empty range of
205+
/// spelled tokens to a (possibly empty) range of expanded tokens. Here is a
206+
/// few examples of expansions:
207+
/// #pragma once // Expands to an empty range.
208+
/// #define FOO 1 2 3 // Expands an empty range.
209+
/// FOO // Expands to "1 2 3".
210+
/// FIXME(ibiryukov): implement this, currently #include expansions are empty.
211+
/// #include <vector> // Expands to tokens produced by the include.
212+
struct Expansion {
213+
llvm::ArrayRef<syntax::Token> Spelled;
214+
llvm::ArrayRef<syntax::Token> Expanded;
215+
};
216+
/// If \p Spelled starts a mapping (e.g. if it's a macro name or '#' starting
217+
/// a preprocessor directive) return the subrange of expanded tokens that the
218+
/// macro expands to.
219+
llvm::Optional<Expansion>
220+
expansionStartingAt(const syntax::Token *Spelled) const;
221+
203222
/// Lexed tokens of a file before preprocessing. E.g. for the following input
204223
/// #define DECL(name) int name = 10
205224
/// DECL(a);

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,8 +1915,15 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
19151915
Align = Target->getDoubleAlign();
19161916
break;
19171917
case BuiltinType::LongDouble:
1918-
Width = Target->getLongDoubleWidth();
1919-
Align = Target->getLongDoubleAlign();
1918+
if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
1919+
(Target->getLongDoubleWidth() != AuxTarget->getLongDoubleWidth() ||
1920+
Target->getLongDoubleAlign() != AuxTarget->getLongDoubleAlign())) {
1921+
Width = AuxTarget->getLongDoubleWidth();
1922+
Align = AuxTarget->getLongDoubleAlign();
1923+
} else {
1924+
Width = Target->getLongDoubleWidth();
1925+
Align = Target->getLongDoubleAlign();
1926+
}
19201927
break;
19211928
case BuiltinType::Float128:
19221929
if (Target->hasFloat128Type() || !getLangOpts().OpenMP ||

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,17 +2607,33 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
26072607
case BuiltinType::Double:
26082608
Out << 'd';
26092609
break;
2610-
case BuiltinType::LongDouble:
2611-
Out << (getASTContext().getTargetInfo().useFloat128ManglingForLongDouble()
2612-
? 'g'
2613-
: 'e');
2610+
case BuiltinType::LongDouble: {
2611+
bool UseFloat128Mangling =
2612+
getASTContext().getTargetInfo().useFloat128ManglingForLongDouble();
2613+
if (getASTContext().getLangOpts().OpenMP &&
2614+
getASTContext().getLangOpts().OpenMPIsDevice) {
2615+
UseFloat128Mangling = getASTContext()
2616+
.getAuxTargetInfo()
2617+
->useFloat128ManglingForLongDouble();
2618+
}
2619+
Out << (UseFloat128Mangling ? 'g' : 'e');
26142620
break;
2615-
case BuiltinType::Float128:
2616-
if (getASTContext().getTargetInfo().useFloat128ManglingForLongDouble())
2621+
}
2622+
case BuiltinType::Float128: {
2623+
bool UseFloat128Mangling =
2624+
getASTContext().getTargetInfo().useFloat128ManglingForLongDouble();
2625+
if (getASTContext().getLangOpts().OpenMP &&
2626+
getASTContext().getLangOpts().OpenMPIsDevice) {
2627+
UseFloat128Mangling = getASTContext()
2628+
.getAuxTargetInfo()
2629+
->useFloat128ManglingForLongDouble();
2630+
}
2631+
if (UseFloat128Mangling)
26172632
Out << "U10__float128"; // Match the GCC mangling
26182633
else
26192634
Out << 'g';
26202635
break;
2636+
}
26212637
case BuiltinType::NullPtr:
26222638
Out << "Dn";
26232639
break;

clang/lib/Basic/Targets/RISCV.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class RISCVTargetInfo : public TargetInfo {
3535
RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
3636
: TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
3737
HasD(false), HasC(false) {
38-
TLSSupported = false;
3938
LongDoubleWidth = 128;
4039
LongDoubleAlign = 128;
4140
LongDoubleFormat = &llvm::APFloat::IEEEquad();

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5607,6 +5607,7 @@ class ARMABIInfo : public SwiftABIInfo {
56075607
uint64_t Members) const;
56085608
ABIArgInfo coerceIllegalVector(QualType Ty) const;
56095609
bool isIllegalVectorType(QualType Ty) const;
5610+
bool containsAnyFP16Vectors(QualType Ty) const;
56105611

56115612
bool isHomogeneousAggregateBaseType(QualType Ty) const override;
56125613
bool isHomogeneousAggregateSmallEnough(const Type *Ty,
@@ -5806,9 +5807,7 @@ ABIArgInfo ARMABIInfo::classifyHomogeneousAggregate(QualType Ty,
58065807
// Base can be a floating-point or a vector.
58075808
if (const VectorType *VT = Base->getAs<VectorType>()) {
58085809
// FP16 vectors should be converted to integer vectors
5809-
if (!getTarget().hasLegalHalfType() &&
5810-
(VT->getElementType()->isFloat16Type() ||
5811-
VT->getElementType()->isHalfType())) {
5810+
if (!getTarget().hasLegalHalfType() && containsAnyFP16Vectors(Ty)) {
58125811
uint64_t Size = getContext().getTypeSize(VT);
58135812
llvm::Type *NewVecTy = llvm::VectorType::get(
58145813
llvm::Type::getInt32Ty(getVMContext()), Size / 32);
@@ -6169,6 +6168,37 @@ bool ARMABIInfo::isIllegalVectorType(QualType Ty) const {
61696168
return false;
61706169
}
61716170

6171+
/// Return true if a type contains any 16-bit floating point vectors
6172+
bool ARMABIInfo::containsAnyFP16Vectors(QualType Ty) const {
6173+
if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) {
6174+
uint64_t NElements = AT->getSize().getZExtValue();
6175+
if (NElements == 0)
6176+
return false;
6177+
return containsAnyFP16Vectors(AT->getElementType());
6178+
} else if (const RecordType *RT = Ty->getAs<RecordType>()) {
6179+
const RecordDecl *RD = RT->getDecl();
6180+
6181+
// If this is a C++ record, check the bases first.
6182+
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
6183+
if (llvm::any_of(CXXRD->bases(), [this](const CXXBaseSpecifier &B) {
6184+
return containsAnyFP16Vectors(B.getType());
6185+
}))
6186+
return true;
6187+
6188+
if (llvm::any_of(RD->fields(), [this](FieldDecl *FD) {
6189+
return FD && containsAnyFP16Vectors(FD->getType());
6190+
}))
6191+
return true;
6192+
6193+
return false;
6194+
} else {
6195+
if (const VectorType *VT = Ty->getAs<VectorType>())
6196+
return (VT->getElementType()->isFloat16Type() ||
6197+
VT->getElementType()->isHalfType());
6198+
return false;
6199+
}
6200+
}
6201+
61726202
bool ARMABIInfo::isLegalVectorTypeForSwift(CharUnits vectorSize,
61736203
llvm::Type *eltTy,
61746204
unsigned numElts) const {
@@ -6300,7 +6330,9 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
63006330
static bool isUnsupportedType(ASTContext &Context, QualType T) {
63016331
if (!Context.getTargetInfo().hasFloat16Type() && T->isFloat16Type())
63026332
return true;
6303-
if (!Context.getTargetInfo().hasFloat128Type() && T->isFloat128Type())
6333+
if (!Context.getTargetInfo().hasFloat128Type() &&
6334+
(T->isFloat128Type() ||
6335+
(T->isRealFloatingType() && Context.getTypeSize(T) == 128)))
63046336
return true;
63056337
if (!Context.getTargetInfo().hasInt128Type() && T->isIntegerType() &&
63066338
Context.getTypeSize(T) > 64)

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
5757
const llvm::opt::ArgList &Args);
5858
unsigned GetDefaultDwarfVersion() const override { return 5; }
5959
bool IsIntegratedAssemblerDefault() const override { return true; }
60+
bool IsMathErrnoDefault() const override { return false; }
61+
6062
llvm::opt::DerivedArgList *
6163
TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
6264
Action::OffloadKind DeviceOffloadKind) const override;

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs,
165165
return;
166166
}
167167
// Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") ))
168-
while (true) {
169-
// Allow empty/non-empty attributes. ((__vector_size__(16),,,,))
170-
if (TryConsumeToken(tok::comma))
171-
continue;
168+
do {
169+
// Eat preceeding commas to allow __attribute__((,,,foo))
170+
while (TryConsumeToken(tok::comma))
171+
;
172172

173173
// Expect an identifier or declaration specifier (const, int, etc.)
174174
if (Tok.isAnnotation())
@@ -213,7 +213,7 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs,
213213
Eof.startToken();
214214
Eof.setLocation(Tok.getLocation());
215215
LA->Toks.push_back(Eof);
216-
}
216+
} while (Tok.is(tok::comma));
217217

218218
if (ExpectAndConsume(tok::r_paren))
219219
SkipUntil(tok::r_paren, StopAtSemi);

clang/lib/Sema/SemaDecl.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11905,8 +11905,11 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1190511905
while (prev && prev->isThisDeclarationADefinition())
1190611906
prev = prev->getPreviousDecl();
1190711907

11908-
if (!prev)
11908+
if (!prev) {
1190911909
Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var;
11910+
Diag(var->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
11911+
<< /* variable */ 0;
11912+
}
1191011913
}
1191111914

1191211915
// Cache the result of checking for constant initialization.
@@ -12792,8 +12795,9 @@ void Sema::ActOnFinishInlineFunctionDef(FunctionDecl *D) {
1279212795
Consumer.HandleInlineFunctionDefinition(D);
1279312796
}
1279412797

12795-
static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
12796-
const FunctionDecl*& PossibleZeroParamPrototype) {
12798+
static bool
12799+
ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
12800+
const FunctionDecl *&PossiblePrototype) {
1279712801
// Don't warn about invalid declarations.
1279812802
if (FD->isInvalidDecl())
1279912803
return false;
@@ -12830,21 +12834,18 @@ static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
1283012834
if (FD->isDeleted())
1283112835
return false;
1283212836

12833-
bool MissingPrototype = true;
1283412837
for (const FunctionDecl *Prev = FD->getPreviousDecl();
1283512838
Prev; Prev = Prev->getPreviousDecl()) {
1283612839
// Ignore any declarations that occur in function or method
1283712840
// scope, because they aren't visible from the header.
1283812841
if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
1283912842
continue;
1284012843

12841-
MissingPrototype = !Prev->getType()->isFunctionProtoType();
12842-
if (FD->getNumParams() == 0)
12843-
PossibleZeroParamPrototype = Prev;
12844-
break;
12844+
PossiblePrototype = Prev;
12845+
return Prev->getType()->isFunctionNoProtoType();
1284512846
}
1284612847

12847-
return MissingPrototype;
12848+
return true;
1284812849
}
1284912850

1285012851
void
@@ -13364,22 +13365,30 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1336413365
// prototype declaration. This warning is issued even if the
1336513366
// definition itself provides a prototype. The aim is to detect
1336613367
// global functions that fail to be declared in header files.
13367-
const FunctionDecl *PossibleZeroParamPrototype = nullptr;
13368-
if (ShouldWarnAboutMissingPrototype(FD, PossibleZeroParamPrototype)) {
13368+
const FunctionDecl *PossiblePrototype = nullptr;
13369+
if (ShouldWarnAboutMissingPrototype(FD, PossiblePrototype)) {
1336913370
Diag(FD->getLocation(), diag::warn_missing_prototype) << FD;
1337013371

13371-
if (PossibleZeroParamPrototype) {
13372+
if (PossiblePrototype) {
1337213373
// We found a declaration that is not a prototype,
1337313374
// but that could be a zero-parameter prototype
13374-
if (TypeSourceInfo *TI =
13375-
PossibleZeroParamPrototype->getTypeSourceInfo()) {
13375+
if (TypeSourceInfo *TI = PossiblePrototype->getTypeSourceInfo()) {
1337613376
TypeLoc TL = TI->getTypeLoc();
1337713377
if (FunctionNoProtoTypeLoc FTL = TL.getAs<FunctionNoProtoTypeLoc>())
13378-
Diag(PossibleZeroParamPrototype->getLocation(),
13378+
Diag(PossiblePrototype->getLocation(),
1337913379
diag::note_declaration_not_a_prototype)
13380-
<< PossibleZeroParamPrototype
13381-
<< FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");
13380+
<< (FD->getNumParams() != 0)
13381+
<< (FD->getNumParams() == 0
13382+
? FixItHint::CreateInsertion(FTL.getRParenLoc(), "void")
13383+
: FixItHint{});
1338213384
}
13385+
} else {
13386+
Diag(FD->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
13387+
<< /* function */ 1
13388+
<< (FD->getStorageClass() == SC_None
13389+
? FixItHint::CreateInsertion(FD->getTypeSpecStartLoc(),
13390+
"static ")
13391+
: FixItHint{});
1338313392
}
1338413393

1338513394
// GNU warning -Wstrict-prototypes

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,9 @@ void Sema::checkOpenMPDeviceExpr(const Expr *E) {
15761576
"OpenMP device compilation mode is expected.");
15771577
QualType Ty = E->getType();
15781578
if ((Ty->isFloat16Type() && !Context.getTargetInfo().hasFloat16Type()) ||
1579-
(Ty->isFloat128Type() && !Context.getTargetInfo().hasFloat128Type()) ||
1579+
((Ty->isFloat128Type() ||
1580+
(Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128)) &&
1581+
!Context.getTargetInfo().hasFloat128Type()) ||
15801582
(Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
15811583
!Context.getTargetInfo().hasInt128Type()))
15821584
targetDiag(E->getExprLoc(), diag::err_type_unsupported)

clang/lib/Tooling/Syntax/Tokens.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,32 @@ TokenBuffer::spelledForExpanded(llvm::ArrayRef<syntax::Token> Expanded) const {
199199
: LastSpelled + 1);
200200
}
201201

202+
llvm::Optional<TokenBuffer::Expansion>
203+
TokenBuffer::expansionStartingAt(const syntax::Token *Spelled) const {
204+
assert(Spelled);
205+
assert(Spelled->location().isFileID() && "not a spelled token");
206+
auto FileIt = Files.find(SourceMgr->getFileID(Spelled->location()));
207+
assert(FileIt != Files.end() && "file not tracked by token buffer");
208+
209+
auto &File = FileIt->second;
210+
assert(File.SpelledTokens.data() <= Spelled &&
211+
Spelled < (File.SpelledTokens.data() + File.SpelledTokens.size()));
212+
213+
unsigned SpelledIndex = Spelled - File.SpelledTokens.data();
214+
auto M = llvm::bsearch(File.Mappings, [&](const Mapping &M) {
215+
return SpelledIndex <= M.BeginSpelled;
216+
});
217+
if (M == File.Mappings.end() || M->BeginSpelled != SpelledIndex)
218+
return llvm::None;
219+
220+
Expansion E;
221+
E.Spelled = llvm::makeArrayRef(File.SpelledTokens.data() + M->BeginSpelled,
222+
File.SpelledTokens.data() + M->EndSpelled);
223+
E.Expanded = llvm::makeArrayRef(ExpandedTokens.data() + M->BeginExpanded,
224+
ExpandedTokens.data() + M->EndExpanded);
225+
return E;
226+
}
227+
202228
std::vector<syntax::Token> syntax::tokenize(FileID FID, const SourceManager &SM,
203229
const LangOptions &LO) {
204230
std::vector<syntax::Token> Tokens;

0 commit comments

Comments
 (0)