Skip to content

Commit a1fa683

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:dc129d6f715c into amd-gfx:bedba19995b8
Local branch amd-gfx bedba19 Merged main:ea2036e1e56b into amd-gfx:e1b9ddbd68c9 Remote branch main dc129d6 [libc++] Add std::fpclassify overloads for floating-point. (llvm#67913)
2 parents bedba19 + dc129d6 commit a1fa683

File tree

63 files changed

+385
-738
lines changed

Some content is hidden

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

63 files changed

+385
-738
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ Bug Fixes in This Version
343343
- Fix a crash when evaluating value-dependent structured binding
344344
variables at compile time.
345345
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
346+
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
347+
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
346348

347349
Bug Fixes to Compiler Builtins
348350
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ class ASTWriter : public ASTDeserializationListener,
613613
/// the module but currently is merely a random 32-bit number.
614614
ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
615615
Module *WritingModule, StringRef isysroot,
616-
bool hasErrors = false,
617616
bool ShouldCacheASTInMemory = false);
618617

619618
/// Emit a token.

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,12 +2341,9 @@ bool ASTUnit::Save(StringRef File) {
23412341
return false;
23422342
}
23432343

2344-
static bool serializeUnit(ASTWriter &Writer,
2345-
SmallVectorImpl<char> &Buffer,
2346-
Sema &S,
2347-
bool hasErrors,
2348-
raw_ostream &OS) {
2349-
Writer.WriteAST(S, std::string(), nullptr, "", hasErrors);
2344+
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
2345+
Sema &S, raw_ostream &OS) {
2346+
Writer.WriteAST(S, std::string(), nullptr, "");
23502347

23512348
// Write the generated bitstream to "Out".
23522349
if (!Buffer.empty())
@@ -2356,18 +2353,14 @@ static bool serializeUnit(ASTWriter &Writer,
23562353
}
23572354

23582355
bool ASTUnit::serialize(raw_ostream &OS) {
2359-
// For serialization we are lenient if the errors were only warn-as-error kind.
2360-
bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred();
2361-
23622356
if (WriterData)
2363-
return serializeUnit(WriterData->Writer, WriterData->Buffer,
2364-
getSema(), hasErrors, OS);
2357+
return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS);
23652358

23662359
SmallString<128> Buffer;
23672360
llvm::BitstreamWriter Stream(Buffer);
23682361
InMemoryModuleCache ModuleCache;
23692362
ASTWriter Writer(Stream, Buffer, ModuleCache, {});
2370-
return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS);
2363+
return serializeUnit(Writer, Buffer, getSema(), OS);
23712364
}
23722365

23732366
using SLocRemap = ContinuousRangeMap<unsigned, int, 2>;

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4622,12 +4622,12 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const {
46224622

46234623
ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile,
46244624
Module *WritingModule, StringRef isysroot,
4625-
bool hasErrors,
46264625
bool ShouldCacheASTInMemory) {
46274626
llvm::TimeTraceScope scope("WriteAST", OutputFile);
46284627
WritingAST = true;
46294628

4630-
ASTHasCompilerErrors = hasErrors;
4629+
ASTHasCompilerErrors =
4630+
SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();
46314631

46324632
// Emit the file header.
46334633
Stream.Emit((unsigned)'C', 8);

clang/lib/Serialization/GeneratePCH.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
6565

6666
// Emit the PCH file to the Buffer.
6767
assert(SemaPtr && "No Sema?");
68-
Buffer->Signature =
69-
Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
70-
// For serialization we are lenient if the errors were
71-
// only warn-as-error kind.
72-
PP.getDiagnostics().hasUncompilableErrorOccurred(),
73-
ShouldCacheASTInMemory);
68+
Buffer->Signature = Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
69+
ShouldCacheASTInMemory);
7470

7571
Buffer->IsComplete = true;
7672
}

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,23 +2690,28 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
26902690
OS << ", ";
26912691
emitFormInitializer(OS, Spellings[0], "0");
26922692
} else {
2693-
OS << ", (\n";
2693+
OS << ", [&]() {\n";
2694+
OS << " switch (S) {\n";
26942695
std::set<std::string> Uniques;
26952696
unsigned Idx = 0;
26962697
for (auto I = Spellings.begin(), E = Spellings.end(); I != E;
26972698
++I, ++Idx) {
26982699
const FlattenedSpelling &S = *I;
26992700
const auto &Name = SemanticToSyntacticMap[Idx];
27002701
if (Uniques.insert(Name).second) {
2701-
OS << " S == " << Name << " ? AttributeCommonInfo::Form";
2702+
OS << " case " << Name << ":\n";
2703+
OS << " return AttributeCommonInfo::Form";
27022704
emitFormInitializer(OS, S, Name);
2703-
OS << " :\n";
2705+
OS << ";\n";
27042706
}
27052707
}
2706-
OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), "
2707-
<< " AttributeCommonInfo::Form";
2708+
OS << " default:\n";
2709+
OS << " llvm_unreachable(\"Unknown attribute spelling!\");\n"
2710+
<< " return AttributeCommonInfo::Form";
27082711
emitFormInitializer(OS, Spellings[0], "0");
2709-
OS << "))";
2712+
OS << ";\n"
2713+
<< " }\n"
2714+
<< " }()";
27102715
}
27112716

27122717
OS << ");\n";

libcxx/include/math.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,19 @@ namespace __math {
387387

388388
// fpclassify
389389

390-
template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
391-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
390+
// template on non-double overloads to make them weaker than same overloads from MSVC runtime
391+
template <class = int>
392+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
393+
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
394+
}
395+
396+
template <class = int>
397+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(double __x) _NOEXCEPT {
398+
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
399+
}
400+
401+
template <class = int>
402+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(long double __x) _NOEXCEPT {
392403
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
393404
}
394405

libcxx/test/std/numerics/c.math/cmath.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,20 @@ void test_fpclassify()
603603
static_assert((std::is_same<decltype(std::fpclassify(0)), int>::value), "");
604604
static_assert((std::is_same<decltype(std::fpclassify((long double)0)), int>::value), "");
605605
static_assert((std::is_same<decltype(fpclassify(Ambiguous())), Ambiguous>::value), "");
606+
static_assert((std::is_same<decltype(fpclassify(Value<float>())), int>::value), "");
607+
static_assert((std::is_same<decltype(fpclassify(Value<double>())), int>::value), "");
608+
static_assert((std::is_same<decltype(fpclassify(Value<long double>())), int>::value), "");
609+
ASSERT_NOEXCEPT(std::fpclassify((float)0));
610+
ASSERT_NOEXCEPT(std::fpclassify((double)0));
611+
ASSERT_NOEXCEPT(std::fpclassify((long double)0));
612+
ASSERT_NOEXCEPT(std::fpclassify(0));
606613
assert(std::fpclassify(-1.0) == FP_NORMAL);
607614
assert(std::fpclassify(0) == FP_ZERO);
608615
assert(std::fpclassify(1) == FP_NORMAL);
609616
assert(std::fpclassify(-1) == FP_NORMAL);
610617
assert(std::fpclassify(std::numeric_limits<int>::max()) == FP_NORMAL);
611618
assert(std::fpclassify(std::numeric_limits<int>::min()) == FP_NORMAL);
619+
assert(std::fpclassify(Value<double, 1>()) == FP_NORMAL);
612620
}
613621

614622
void test_isfinite()

llvm/include/llvm/Analysis/BlockFrequencyInfo.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ class BlockFrequencyInfo {
7373
/// Returns the estimated profile count of \p Freq.
7474
/// This uses the frequency \p Freq and multiplies it by
7575
/// the enclosing function's count (if available) and returns the value.
76-
std::optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
76+
std::optional<uint64_t> getProfileCountFromFreq(BlockFrequency Freq) const;
7777

7878
/// Returns true if \p BB is an irreducible loop header
7979
/// block. Otherwise false.
8080
bool isIrrLoopHeader(const BasicBlock *BB);
8181

8282
// Set the frequency of the given basic block.
83-
void setBlockFreq(const BasicBlock *BB, uint64_t Freq);
83+
void setBlockFreq(const BasicBlock *BB, BlockFrequency Freq);
8484

8585
/// Set the frequency of \p ReferenceBB to \p Freq and scale the frequencies
8686
/// of the blocks in \p BlocksToScale such that their frequencies relative
8787
/// to \p ReferenceBB remain unchanged.
88-
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, uint64_t Freq,
88+
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, BlockFrequency Freq,
8989
SmallPtrSetImpl<BasicBlock *> &BlocksToScale);
9090

9191
/// calculate - compute block frequency info for the given function.
@@ -94,13 +94,13 @@ class BlockFrequencyInfo {
9494

9595
// Print the block frequency Freq to OS using the current functions entry
9696
// frequency to convert freq into a relative decimal form.
97-
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
97+
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
9898

9999
// Convenience method that attempts to look up the frequency associated with
100100
// BB and print it to OS.
101101
raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;
102102

103-
uint64_t getEntryFreq() const;
103+
BlockFrequency getEntryFreq() const;
104104
void releaseMemory();
105105
void print(raw_ostream &OS) const;
106106

llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,18 @@ class BlockFrequencyInfoImplBase {
527527
getBlockProfileCount(const Function &F, const BlockNode &Node,
528528
bool AllowSynthetic = false) const;
529529
std::optional<uint64_t>
530-
getProfileCountFromFreq(const Function &F, uint64_t Freq,
530+
getProfileCountFromFreq(const Function &F, BlockFrequency Freq,
531531
bool AllowSynthetic = false) const;
532532
bool isIrrLoopHeader(const BlockNode &Node);
533533

534-
void setBlockFreq(const BlockNode &Node, uint64_t Freq);
534+
void setBlockFreq(const BlockNode &Node, BlockFrequency Freq);
535535

536536
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockNode &Node) const;
537-
raw_ostream &printBlockFreq(raw_ostream &OS,
538-
const BlockFrequency &Freq) const;
537+
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
539538

540-
uint64_t getEntryFreq() const {
539+
BlockFrequency getEntryFreq() const {
541540
assert(!Freqs.empty());
542-
return Freqs[0].Integer;
541+
return BlockFrequency(Freqs[0].Integer);
543542
}
544543
};
545544

@@ -1029,7 +1028,7 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
10291028
}
10301029

10311030
std::optional<uint64_t>
1032-
getProfileCountFromFreq(const Function &F, uint64_t Freq,
1031+
getProfileCountFromFreq(const Function &F, BlockFrequency Freq,
10331032
bool AllowSynthetic = false) const {
10341033
return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq,
10351034
AllowSynthetic);
@@ -1039,7 +1038,7 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
10391038
return BlockFrequencyInfoImplBase::isIrrLoopHeader(getNode(BB));
10401039
}
10411040

1042-
void setBlockFreq(const BlockT *BB, uint64_t Freq);
1041+
void setBlockFreq(const BlockT *BB, BlockFrequency Freq);
10431042

10441043
void forgetBlock(const BlockT *BB) {
10451044
// We don't erase corresponding items from `Freqs`, `RPOT` and other to
@@ -1145,12 +1144,13 @@ void BlockFrequencyInfoImpl<BT>::calculate(const FunctionT &F,
11451144
// blocks and unknown blocks.
11461145
for (const BlockT &BB : F)
11471146
if (!Nodes.count(&BB))
1148-
setBlockFreq(&BB, 0);
1147+
setBlockFreq(&BB, BlockFrequency());
11491148
}
11501149
}
11511150

11521151
template <class BT>
1153-
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB, uint64_t Freq) {
1152+
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
1153+
BlockFrequency Freq) {
11541154
if (Nodes.count(BB))
11551155
BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);
11561156
else {

0 commit comments

Comments
 (0)