Skip to content

Commit 99c3c2f

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:b861457c904c into amd-gfx:6cf360cc101c
Local branch amd-gfx 6cf360c Merged main:451255b207c8 into amd-gfx:03a4dc920122 Remote branch main b861457 [libc++] Fix a segfault in weak_ptr(const weak_ptr<Y>&) (llvm#67956)
2 parents 6cf360c + b861457 commit 99c3c2f

File tree

37 files changed

+503
-184
lines changed

37 files changed

+503
-184
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
10761076
DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
10771077
DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
10781078
DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
1079+
if (TI.hasFloat128Type())
1080+
DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
10791081

10801082
// Define a __POINTER_WIDTH__ macro for stdint.h.
10811083
Builder.defineMacro("__POINTER_WIDTH__",

clang/test/Preprocessor/init-x86.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,21 @@
10231023
// X86_64-LINUX:#define __DBL_MIN_EXP__ (-1021)
10241024
// X86_64-LINUX:#define __DBL_MIN__ 2.2250738585072014e-308
10251025
// X86_64-LINUX:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
1026+
// X86_64-LINUX:#define __FLOAT128__ 1
1027+
// X86_64-LINUX:#define __FLT128_DECIMAL_DIG__ 36
1028+
// X86_64-LINUX:#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966Q
1029+
// X86_64-LINUX:#define __FLT128_DIG__ 33
1030+
// X86_64-LINUX:#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34Q
1031+
// X86_64-LINUX:#define __FLT128_HAS_DENORM__ 1
1032+
// X86_64-LINUX:#define __FLT128_HAS_INFINITY__ 1
1033+
// X86_64-LINUX:#define __FLT128_HAS_QUIET_NAN__ 1
1034+
// X86_64-LINUX:#define __FLT128_MANT_DIG__ 113
1035+
// X86_64-LINUX:#define __FLT128_MAX_10_EXP__ 4932
1036+
// X86_64-LINUX:#define __FLT128_MAX_EXP__ 16384
1037+
// X86_64-LINUX:#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932Q
1038+
// X86_64-LINUX:#define __FLT128_MIN_10_EXP__ (-4931)
1039+
// X86_64-LINUX:#define __FLT128_MIN_EXP__ (-16381)
1040+
// X86_64-LINUX:#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932Q
10261041
// X86_64-LINUX:#define __FLT_DENORM_MIN__ 1.40129846e-45F
10271042
// X86_64-LINUX:#define __FLT_DIG__ 6
10281043
// X86_64-LINUX:#define __FLT_EPSILON__ 1.19209290e-7F

clang/test/Preprocessor/init.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,20 @@
15761576
// EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
15771577
// WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
15781578
// WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
1579+
// WEBASSEMBLY-NEXT:#define __FLT128_DECIMAL_DIG__ 36
1580+
// WEBASSEMBLY-NEXT:#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966Q
1581+
// WEBASSEMBLY-NEXT:#define __FLT128_DIG__ 33
1582+
// WEBASSEMBLY-NEXT:#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34Q
1583+
// WEBASSEMBLY-NEXT:#define __FLT128_HAS_DENORM__ 1
1584+
// WEBASSEMBLY-NEXT:#define __FLT128_HAS_INFINITY__ 1
1585+
// WEBASSEMBLY-NEXT:#define __FLT128_HAS_QUIET_NAN__ 1
1586+
// WEBASSEMBLY-NEXT:#define __FLT128_MANT_DIG__ 113
1587+
// WEBASSEMBLY-NEXT:#define __FLT128_MAX_10_EXP__ 4932
1588+
// WEBASSEMBLY-NEXT:#define __FLT128_MAX_EXP__ 16384
1589+
// WEBASSEMBLY-NEXT:#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932Q
1590+
// WEBASSEMBLY-NEXT:#define __FLT128_MIN_10_EXP__ (-4931)
1591+
// WEBASSEMBLY-NEXT:#define __FLT128_MIN_EXP__ (-16381)
1592+
// WEBASSEMBLY-NEXT:#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932Q
15791593
// WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
15801594
// WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
15811595
// WEBASSEMBLY-NOT:#define __FLT16_DIG__

libcxx/include/__memory/shared_ptr.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,11 +1727,11 @@ template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> >
17271727
inline
17281728
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r)
17291729
_NOEXCEPT
1730-
: __ptr_(__r.__ptr_),
1731-
__cntrl_(__r.__cntrl_)
1730+
: __ptr_(nullptr),
1731+
__cntrl_(nullptr)
17321732
{
1733-
if (__cntrl_)
1734-
__cntrl_->__add_weak();
1733+
shared_ptr<_Yp> __s = __r.lock();
1734+
*this = weak_ptr<_Tp>(__s);
17351735
}
17361736

17371737
template<class _Tp>
@@ -1749,11 +1749,12 @@ template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> >
17491749
inline
17501750
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r)
17511751
_NOEXCEPT
1752-
: __ptr_(__r.__ptr_),
1753-
__cntrl_(__r.__cntrl_)
1752+
: __ptr_(nullptr),
1753+
__cntrl_(nullptr)
17541754
{
1755-
__r.__ptr_ = nullptr;
1756-
__r.__cntrl_ = nullptr;
1755+
shared_ptr<_Yp> __s = __r.lock();
1756+
*this = weak_ptr<_Tp>(__s);
1757+
__r.reset();
17571758
}
17581759

17591760
template<class _Tp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <memory>
10+
11+
// weak_ptr
12+
13+
// template<class Y> weak_ptr(const weak_ptr<Y>& r);
14+
// template<class Y> weak_ptr(weak_ptr<Y>&& r);
15+
//
16+
// Regression test for https://github.com/llvm/llvm-project/issues/40459
17+
// Verify that these constructors never attempt a derived-to-virtual-base
18+
// conversion on a dangling weak_ptr.
19+
20+
#include <cassert>
21+
#include <cstring>
22+
#include <memory>
23+
#include <utility>
24+
25+
#include "test_macros.h"
26+
27+
struct A {
28+
int i;
29+
virtual ~A() {}
30+
};
31+
struct B : public virtual A {
32+
int j;
33+
};
34+
struct Deleter {
35+
void operator()(void*) const {
36+
// do nothing
37+
}
38+
};
39+
40+
int main(int, char**) {
41+
#if TEST_STD_VER >= 11
42+
alignas(B) char buffer[sizeof(B)];
43+
#else
44+
std::aligned_storage<sizeof(B), std::alignment_of<B>::value>::type buffer;
45+
#endif
46+
B* pb = ::new ((void*)&buffer) B();
47+
std::shared_ptr<B> sp = std::shared_ptr<B>(pb, Deleter());
48+
std::weak_ptr<B> wp = sp;
49+
sp = nullptr;
50+
assert(wp.expired());
51+
52+
// Overwrite the B object with junk.
53+
std::memset(&buffer, '*', sizeof(buffer));
54+
55+
std::weak_ptr<A> wq = wp;
56+
assert(wq.expired());
57+
std::weak_ptr<A> wr = std::move(wp);
58+
assert(wr.expired());
59+
60+
return 0;
61+
}

libunwind/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(LIBUNWIND_C_SOURCES
1616
UnwindLevel1.c
1717
UnwindLevel1-gcc-ext.c
1818
Unwind-sjlj.c
19+
Unwind-wasm.c
1920
)
2021
set_source_files_properties(${LIBUNWIND_C_SOURCES}
2122
PROPERTIES

libunwind/src/Unwind-wasm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "config.h"
14-
#include "unwind.h"
1513
#include <stdbool.h>
16-
#include <threads.h>
14+
15+
#include "config.h"
1716

1817
#ifdef __USING_WASM_EXCEPTIONS__
1918

19+
#include "unwind.h"
20+
#include <threads.h>
21+
2022
_Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action actions,
2123
uint64_t exceptionClass,
2224
_Unwind_Exception *unwind_exception,
@@ -118,4 +120,4 @@ _Unwind_GetRegionStart(struct _Unwind_Context *context) {
118120
return 0;
119121
}
120122

121-
#endif
123+
#endif // defined(__USING_WASM_EXCEPTIONS__)

lld/COFF/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ enum class ExportSource {
4848
ModuleDefinition,
4949
};
5050

51+
enum class EmitKind { Obj, LLVM };
52+
5153
// Represents an /export option.
5254
struct Export {
5355
StringRef name; // N in /export:N or /export:E=N
@@ -311,6 +313,7 @@ struct Configuration {
311313
bool pseudoRelocs = false;
312314
bool stdcallFixup = false;
313315
bool writeCheckSum = false;
316+
EmitKind emit = EmitKind::Obj;
314317
};
315318

316319
} // namespace lld::coff

lld/COFF/Driver.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,17 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18521852
if (args.hasArg(OPT_lldsavetemps))
18531853
config->saveTemps = true;
18541854

1855+
// Handle /lldemit
1856+
if (auto *arg = args.getLastArg(OPT_lldemit)) {
1857+
StringRef s = arg->getValue();
1858+
if (s == "obj")
1859+
config->emit = EmitKind::Obj;
1860+
else if (s == "llvm")
1861+
config->emit = EmitKind::LLVM;
1862+
else
1863+
error("/lldemit: unknown option: " + s);
1864+
}
1865+
18551866
// Handle /kill-at
18561867
if (args.hasArg(OPT_kill_at))
18571868
config->killAt = true;
@@ -2395,7 +2406,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
23952406
// If -thinlto-index-only is given, we should create only "index
23962407
// files" and not object files. Index file creation is already done
23972408
// in addCombinedLTOObject, so we are done if that's the case.
2398-
if (config->thinLTOIndexOnly)
2409+
// Likewise, don't emit object files for other /lldemit options.
2410+
if (config->emit != EmitKind::Obj || config->thinLTOIndexOnly)
23992411
return;
24002412

24012413
// If we generated native object files from bitcode files, this resolves

lld/COFF/LTO.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ lto::Config BitcodeCompiler::createConfig() {
8787
c.RunCSIRInstr = ctx.config.ltoCSProfileGenerate;
8888
c.PGOWarnMismatch = ctx.config.ltoPGOWarnMismatch;
8989

90+
if (ctx.config.emit == EmitKind::LLVM) {
91+
c.PostInternalizeModuleHook = [this](size_t task, const Module &m) {
92+
if (std::unique_ptr<raw_fd_ostream> os =
93+
openLTOOutputFile(ctx.config.outputFile))
94+
WriteBitcodeToFile(m, *os, false);
95+
return false;
96+
};
97+
}
98+
9099
if (ctx.config.saveTemps)
91100
checkError(c.addSaveTemps(std::string(ctx.config.outputFile) + ".",
92101
/*UseInputModulePath*/ true));

lld/COFF/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ defm demangle : B<"demangle",
232232
def include_optional : Joined<["/", "-", "/?", "-?"], "includeoptional:">,
233233
HelpText<"Add symbol as undefined, but allow it to remain undefined">;
234234
def kill_at : F<"kill-at">;
235+
def lldemit : P<"lldemit", "Specify output type">;
235236
def lldmingw : F<"lldmingw">;
236237
def noseh : F<"noseh">;
237238
def osversion : P_priv<"osversion">;

lld/COFF/PDB.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ class DebugSHandler {
187187
/// The object file whose .debug$S sections we're processing.
188188
ObjFile &file;
189189

190-
/// The result of merging type indices.
191-
TpiSource *source;
192-
193190
/// The DEBUG_S_STRINGTABLE subsection. These strings are referred to by
194191
/// index from other records in the .debug$S section. All of these strings
195192
/// need to be added to the global PDB string table, and all references to
@@ -230,11 +227,9 @@ class DebugSHandler {
230227
void addFrameDataSubsection(SectionChunk *debugChunk,
231228
const DebugSubsectionRecord &ss);
232229

233-
void recordStringTableReferences(CVSymbol sym, uint32_t symOffset);
234-
235230
public:
236-
DebugSHandler(PDBLinker &linker, ObjFile &file, TpiSource *source)
237-
: linker(linker), file(file), source(source) {}
231+
DebugSHandler(PDBLinker &linker, ObjFile &file)
232+
: linker(linker), file(file) {}
238233

239234
void handleDebugS(SectionChunk *debugChunk);
240235

@@ -1035,7 +1030,7 @@ void PDBLinker::addDebugSymbols(TpiSource *source) {
10351030
ScopedTimer t(ctx.symbolMergingTimer);
10361031
ExitOnError exitOnErr;
10371032
pdb::DbiStreamBuilder &dbiBuilder = builder.getDbiBuilder();
1038-
DebugSHandler dsh(*this, *source->file, source);
1033+
DebugSHandler dsh(*this, *source->file);
10391034
// Now do all live .debug$S and .debug$F sections.
10401035
for (SectionChunk *debugChunk : source->file->getDebugChunks()) {
10411036
if (!debugChunk->live || debugChunk->getSize() == 0)

lld/test/COFF/lto-emit-llvm.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; REQUIRES: x86
2+
; RUN: llvm-as -o %T/lto.obj %s
3+
4+
; RUN: lld-link /lldemit:llvm /out:%T/lto.bc /entry:main /subsystem:console %T/lto.obj
5+
; RUN: llvm-dis %T/lto.bc -o - | FileCheck %s
6+
7+
; CHECK: define void @main()
8+
9+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10+
target triple = "x86_64-pc-windows-msvc"
11+
12+
define void @main() {
13+
ret void
14+
}

llvm/docs/GitHub.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Create a local branch per commit you want to submit and then push that branch
5050
to your `fork <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks>`_
5151
of the llvm-project and
5252
`create a pull request from the fork <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork>`_.
53+
As GitHub uses the first line of the commit message truncated to 72 characters
54+
as the pull request title, you may have to edit to reword or to undo this
55+
truncation.
5356

5457
Creating Pull Requests with GitHub CLI
5558
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 476570
19+
#define LLVM_MAIN_REVISION 476586
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/MC/MCWin64EH.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,9 @@ static void ARM64EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info,
14021402
// here, but we'd have to emit the pdata, the xdata header, and the
14031403
// epilogue scopes later, since they depend on whether the we need to
14041404
// split the unwind data.
1405+
//
1406+
// If this is fixed, remove code in AArch64ISelLowering.cpp that
1407+
// disables loop alignment on Windows.
14051408
RawFuncLength = GetAbsDifference(streamer, info->FuncletOrFuncEnd,
14061409
info->Begin);
14071410
}

llvm/lib/Object/MachOUniversalWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ buildFatArchList(ArrayRef<Slice> Slices) {
281281
.str()
282282
.c_str());
283283

284-
FatArchTy FatArch;
284+
FatArchTy FatArch = {};
285285
FatArch.cputype = S.getCPUType();
286286
FatArch.cpusubtype = S.getCPUSubType();
287287
FatArch.offset = Offset;

0 commit comments

Comments
 (0)