Skip to content

Commit ae5318a

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:233c3e6c53a5 into amd-gfx:8892e09cb17c
Local branch amd-gfx 8892e09 Merged main:b3fbb67379a4 into amd-gfx:6fa5d2831ccc Remote branch main 233c3e6 [mlir][sparse] remove sparse2sparse path in library (llvm#69247)
2 parents 8892e09 + 233c3e6 commit ae5318a

File tree

44 files changed

+900
-603
lines changed

Some content is hidden

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

44 files changed

+900
-603
lines changed

clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ from multiple translation units.
8888
template <class T>
8989
constexpr T pi = T(3.1415926L);
9090

91+
When :program:`clang-tidy` is invoked with the `--fix-notes` option, this check
92+
provides fixes that automatically add the ``inline`` keyword to discovered
93+
functions. Please note that the addition of the ``inline`` keyword to variables
94+
is not currently supported by this check.
95+
9196
Options
9297
-------
9398

clang/lib/Driver/ToolChains/Cuda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class LLVM_LIBRARY_VISIBILITY FatBinary : public Tool {
110110
// Runs nvlink, which links GPU object files ("cubin" files) into a single file.
111111
class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
112112
public:
113-
Linker(const ToolChain &TC) : Tool("NVPTX::Linker", "fatbinary", TC) {}
113+
Linker(const ToolChain &TC) : Tool("NVPTX::Linker", "nvlink", TC) {}
114114

115115
bool hasIntegratedCPP() const override { return false; }
116116

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,9 +2226,6 @@ bool UnwrappedLineParser::tryToParseLambda() {
22262226
// followed by an `a->b` expression, such as:
22272227
// ([obj func:arg] + a->b)
22282228
// Otherwise the code below would parse as a lambda.
2229-
//
2230-
// FIXME: This heuristic is incorrect for C++20 generic lambdas with
2231-
// explicit template lists: []<bool b = true && false>(U &&u){}
22322229
case tok::plus:
22332230
case tok::minus:
22342231
case tok::exclaim:
@@ -2268,6 +2265,11 @@ bool UnwrappedLineParser::tryToParseLambda() {
22682265
parseRequiresClause(RequiresToken);
22692266
break;
22702267
}
2268+
case tok::equal:
2269+
if (!InTemplateParameterList)
2270+
return true;
2271+
nextToken();
2272+
break;
22712273
default:
22722274
return true;
22732275
}

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,44 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
16201620
EXPECT_TOKEN(Tokens[15], tok::kw_requires, TT_RequiresClause);
16211621
EXPECT_TRUE(Tokens[19]->ClosesRequiresClause);
16221622
EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_LambdaLBrace);
1623+
1624+
Tokens = annotate("[] <typename T = int> (T t) {}");
1625+
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
1626+
EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
1627+
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
1628+
EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
1629+
EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
1630+
1631+
Tokens = annotate("[] <int I = 0> (T t) {}");
1632+
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
1633+
EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
1634+
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
1635+
EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
1636+
EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
1637+
1638+
Tokens = annotate("[] <bool b = false> (T t) {}");
1639+
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
1640+
EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
1641+
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
1642+
EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
1643+
EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
1644+
1645+
Tokens = annotate("[] <bool b = true && false> (T&& t) {}");
1646+
ASSERT_EQ(Tokens.size(), 18u) << Tokens;
1647+
EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
1648+
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
1649+
EXPECT_TOKEN(Tokens[7], tok::ampamp, TT_BinaryOperator);
1650+
EXPECT_TOKEN(Tokens[9], tok::greater, TT_TemplateCloser);
1651+
EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_PointerOrReference);
1652+
EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_LambdaLBrace);
1653+
1654+
Tokens = annotate("[] <typename T = int> requires Foo<T> (T t) {}");
1655+
ASSERT_EQ(Tokens.size(), 20u) << Tokens;
1656+
EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
1657+
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
1658+
EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
1659+
EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause);
1660+
EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
16231661
}
16241662

16251663
TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {

flang/include/flang/Common/real.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ static constexpr int MaxDecimalConversionDigits(int binaryPrecision) {
6363
}
6464
}
6565

66+
static constexpr int MaxHexadecimalConversionDigits(int binaryPrecision) {
67+
return binaryPrecision >= 0 ? (binaryPrecision + 3) / 4 : binaryPrecision;
68+
}
69+
6670
static constexpr int RealKindForPrecision(int binaryPrecision) {
6771
switch (binaryPrecision) {
6872
case 8: // IEEE single (truncated): 1+8+7 with implicit bit
@@ -132,6 +136,9 @@ template <int BINARY_PRECISION> class RealDetails {
132136
static constexpr int maxDecimalConversionDigits{
133137
MaxDecimalConversionDigits(binaryPrecision)};
134138

139+
static constexpr int maxHexadecimalConversionDigits{
140+
MaxHexadecimalConversionDigits(binaryPrecision)};
141+
135142
static_assert(binaryPrecision > 0);
136143
static_assert(exponentBits > 1);
137144
static_assert(exponentBits <= 15);

flang/include/flang/Decimal/binary-floating-point.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@
2121

2222
namespace Fortran::decimal {
2323

24+
enum FortranRounding {
25+
RoundNearest, /* RN and RP */
26+
RoundUp, /* RU */
27+
RoundDown, /* RD */
28+
RoundToZero, /* RZ - no rounding */
29+
RoundCompatible, /* RC: like RN, but ties go away from 0 */
30+
};
31+
2432
template <int BINARY_PRECISION>
2533
class BinaryFloatingPointNumber : public common::RealDetails<BINARY_PRECISION> {
2634
public:
2735
using Details = common::RealDetails<BINARY_PRECISION>;
36+
using Details::binaryPrecision;
2837
using Details::bits;
2938
using Details::decimalPrecision;
3039
using Details::decimalRange;
@@ -33,6 +42,7 @@ class BinaryFloatingPointNumber : public common::RealDetails<BINARY_PRECISION> {
3342
using Details::isImplicitMSB;
3443
using Details::maxDecimalConversionDigits;
3544
using Details::maxExponent;
45+
using Details::maxHexadecimalConversionDigits;
3646
using Details::significandBits;
3747

3848
using RawType = common::HostUnsignedIntType<bits>;
@@ -120,6 +130,55 @@ class BinaryFloatingPointNumber : public common::RealDetails<BINARY_PRECISION> {
120130
InsertExplicitMSB();
121131
}
122132

133+
static constexpr BinaryFloatingPointNumber Infinity(bool isNegative) {
134+
RawType result{RawType{maxExponent} << significandBits};
135+
if (isNegative) {
136+
result |= RawType{1} << (bits - 1);
137+
}
138+
return BinaryFloatingPointNumber{result};
139+
}
140+
141+
// Returns true when the result is exact
142+
constexpr bool RoundToBits(int keepBits, enum FortranRounding mode) {
143+
if (IsNaN() || IsInfinite() || keepBits >= binaryPrecision) {
144+
return true;
145+
}
146+
int lostBits{binaryPrecision - keepBits};
147+
RawType lostMask{static_cast<RawType>((RawType{1} << lostBits) - 1)};
148+
if (RawType lost{static_cast<RawType>(raw_ & lostMask)}; lost != 0) {
149+
bool increase{false};
150+
switch (mode) {
151+
case RoundNearest:
152+
if (lost >> (lostBits - 1) != 0) { // >= tie
153+
if ((lost & (lostMask >> 1)) != 0) {
154+
increase = true; // > tie
155+
} else {
156+
increase = ((raw_ >> lostBits) & 1) != 0; // tie to even
157+
}
158+
}
159+
break;
160+
case RoundUp:
161+
increase = !IsNegative();
162+
break;
163+
case RoundDown:
164+
increase = IsNegative();
165+
break;
166+
case RoundToZero:
167+
break;
168+
case RoundCompatible:
169+
increase = lost >> (lostBits - 1) != 0; // >= tie
170+
break;
171+
}
172+
if (increase) {
173+
raw_ |= lostMask;
174+
Next();
175+
}
176+
return false; // inexact
177+
} else {
178+
return true; // exact
179+
}
180+
}
181+
123182
private:
124183
constexpr void RemoveExplicitMSB() {
125184
if constexpr (!isImplicitMSB) {

flang/include/flang/Decimal/decimal.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ struct ConversionToDecimalResult {
4343
enum ConversionResultFlags flags;
4444
};
4545

46-
enum FortranRounding {
47-
RoundNearest, /* RN and RP */
48-
RoundUp, /* RU */
49-
RoundDown, /* RD */
50-
RoundToZero, /* RZ - no rounding */
51-
RoundCompatible, /* RC: like RN, but ties go away from 0 */
52-
};
53-
5446
/* The "minimize" flag causes the fewest number of output digits
5547
* to be emitted such that reading them back into the same binary
5648
* floating-point format with RoundNearest will return the same

flang/include/flang/Evaluate/characteristics.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,19 @@ class TypeAndShape {
8181
bool operator!=(const TypeAndShape &that) const { return !(*this == that); }
8282

8383
static std::optional<TypeAndShape> Characterize(
84-
const semantics::Symbol &, FoldingContext &, bool invariantOnly = false);
84+
const semantics::Symbol &, FoldingContext &, bool invariantOnly = true);
8585
static std::optional<TypeAndShape> Characterize(
8686
const semantics::DeclTypeSpec &, FoldingContext &,
87-
bool invariantOnly = false);
87+
bool invariantOnly = true);
8888
static std::optional<TypeAndShape> Characterize(
89-
const ActualArgument &, FoldingContext &, bool invariantOnly = false);
89+
const ActualArgument &, FoldingContext &, bool invariantOnly = true);
9090

9191
// General case for Expr<T>, &c.
9292
template <typename A>
9393
static std::optional<TypeAndShape> Characterize(
94-
const A &x, FoldingContext &context, bool invariantOnly = false) {
95-
if (const auto *symbol{UnwrapWholeSymbolDataRef(x)}) {
94+
const A &x, FoldingContext &context, bool invariantOnly = true) {
95+
const auto *symbol{UnwrapWholeSymbolOrComponentDataRef(x)};
96+
if (symbol && !symbol->owner().IsDerivedType()) { // Whole variable
9697
if (auto result{Characterize(*symbol, context, invariantOnly)}) {
9798
return result;
9899
}
@@ -106,6 +107,9 @@ class TypeAndShape {
106107
}
107108
}
108109
}
110+
if (symbol) { // component
111+
result.AcquireAttrs(*symbol);
112+
}
109113
return std::move(result.Rewrite(context));
110114
}
111115
return std::nullopt;
@@ -116,15 +120,21 @@ class TypeAndShape {
116120
static std::optional<TypeAndShape> Characterize(
117121
const Designator<Type<TypeCategory::Character, KIND>> &x,
118122
FoldingContext &context, bool invariantOnly = true) {
119-
if (const auto *symbol{UnwrapWholeSymbolDataRef(x)}) {
123+
const auto *symbol{UnwrapWholeSymbolOrComponentDataRef(x)};
124+
if (symbol && !symbol->owner().IsDerivedType()) { // Whole variable
120125
if (auto result{Characterize(*symbol, context, invariantOnly)}) {
121126
return result;
122127
}
123128
}
124129
if (auto type{x.GetType()}) {
125130
TypeAndShape result{*type, GetShape(context, x, invariantOnly)};
126-
if (auto length{x.LEN()}) {
127-
result.set_LEN(std::move(*length));
131+
if (type->category() == TypeCategory::Character) {
132+
if (auto length{x.LEN()}) {
133+
result.set_LEN(std::move(*length));
134+
}
135+
}
136+
if (symbol) { // component
137+
result.AcquireAttrs(*symbol);
128138
}
129139
return std::move(result.Rewrite(context));
130140
}
@@ -133,7 +143,7 @@ class TypeAndShape {
133143

134144
template <typename A>
135145
static std::optional<TypeAndShape> Characterize(const std::optional<A> &x,
136-
FoldingContext &context, bool invariantOnly = false) {
146+
FoldingContext &context, bool invariantOnly = true) {
137147
if (x) {
138148
return Characterize(*x, context, invariantOnly);
139149
} else {
@@ -142,7 +152,7 @@ class TypeAndShape {
142152
}
143153
template <typename A>
144154
static std::optional<TypeAndShape> Characterize(
145-
A *ptr, FoldingContext &context, bool invariantOnly = false) {
155+
A *ptr, FoldingContext &context, bool invariantOnly = true) {
146156
if (ptr) {
147157
return Characterize(std::as_const(*ptr), context, invariantOnly);
148158
} else {

flang/lib/Semantics/mod-file.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,30 +1183,49 @@ Scope *ModFileReader::Read(const SourceName &name,
11831183
}
11841184
Scope &topScope{isIntrinsic.value_or(false) ? context_.intrinsicModulesScope()
11851185
: context_.globalScope()};
1186-
if (!ancestor) {
1186+
Symbol *moduleSymbol{nullptr};
1187+
if (!ancestor) { // module, not submodule
11871188
parentScope = &topScope;
1189+
auto pair{parentScope->try_emplace(name, UnknownDetails{})};
1190+
if (!pair.second) {
1191+
return nullptr;
1192+
}
1193+
moduleSymbol = &*pair.first->second;
1194+
moduleSymbol->set(Symbol::Flag::ModFile);
11881195
} else if (std::optional<SourceName> parent{GetSubmoduleParent(parseTree)}) {
1196+
// submodule with submodule parent
11891197
parentScope = Read(*parent, false /*not intrinsic*/, ancestor, silent);
11901198
} else {
1199+
// submodule with module parent
11911200
parentScope = ancestor;
11921201
}
1193-
auto pair{parentScope->try_emplace(name, UnknownDetails{})};
1194-
if (!pair.second) {
1195-
return nullptr;
1196-
}
11971202
// Process declarations from the module file
1198-
Symbol &modSymbol{*pair.first->second};
1199-
modSymbol.set(Symbol::Flag::ModFile);
12001203
bool wasInModuleFile{context_.foldingContext().inModuleFile()};
12011204
context_.foldingContext().set_inModuleFile(true);
12021205
ResolveNames(context_, parseTree, topScope);
12031206
context_.foldingContext().set_inModuleFile(wasInModuleFile);
1204-
CHECK(modSymbol.has<ModuleDetails>());
1205-
CHECK(modSymbol.test(Symbol::Flag::ModFile));
1206-
if (isIntrinsic.value_or(false)) {
1207-
modSymbol.attrs().set(Attr::INTRINSIC);
1207+
if (!moduleSymbol) {
1208+
// Submodule symbols' storage are owned by their parents' scopes,
1209+
// but their names are not in their parents' dictionaries -- we
1210+
// don't want to report bogus errors about clashes between submodule
1211+
// names and other objects in the parent scopes.
1212+
if (Scope * submoduleScope{ancestor->FindSubmodule(name)}) {
1213+
moduleSymbol = submoduleScope->symbol();
1214+
if (moduleSymbol) {
1215+
moduleSymbol->set(Symbol::Flag::ModFile);
1216+
}
1217+
}
1218+
}
1219+
if (moduleSymbol) {
1220+
CHECK(moduleSymbol->has<ModuleDetails>());
1221+
CHECK(moduleSymbol->test(Symbol::Flag::ModFile));
1222+
if (isIntrinsic.value_or(false)) {
1223+
moduleSymbol->attrs().set(Attr::INTRINSIC);
1224+
}
1225+
return moduleSymbol->scope();
1226+
} else {
1227+
return nullptr;
12081228
}
1209-
return modSymbol.scope();
12101229
}
12111230

12121231
parser::Message &ModFileReader::Say(const SourceName &name,

flang/lib/Semantics/resolve-names.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3230,7 +3230,11 @@ bool ModuleVisitor::BeginSubmodule(
32303230
}
32313231

32323232
void ModuleVisitor::BeginModule(const parser::Name &name, bool isSubmodule) {
3233-
auto &symbol{MakeSymbol(name, ModuleDetails{isSubmodule})};
3233+
// Submodule symbols are not visible in their parents' scopes.
3234+
Symbol &symbol{isSubmodule ? Resolve(name,
3235+
currScope().MakeSymbol(name.source, Attrs{},
3236+
ModuleDetails{true}))
3237+
: MakeSymbol(name, ModuleDetails{false})};
32343238
auto &details{symbol.get<ModuleDetails>()};
32353239
PushScope(Scope::Kind::Module, &symbol);
32363240
details.set_scope(&currScope());

flang/runtime/descriptor-io.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ static bool DefaultComponentwiseIO(IoStatementState &io,
288288
*compArray.Element<typeInfo::Component>(at)};
289289
if (!DefaultComponentIO<DIR>(
290290
io, component, descriptor, subscripts, handler, table)) {
291-
return false;
291+
// Truncated nonempty namelist input sequence?
292+
auto *listInput{
293+
io.get_if<ListDirectedStatementState<Direction::Input>>()};
294+
return DIR == Direction::Input && (j > 0 || k > 0) && listInput &&
295+
listInput->inNamelistSequence();
292296
}
293297
}
294298
}

0 commit comments

Comments
 (0)