Skip to content

Commit

Permalink
clang: add upstream patch to fix assertion failure
Browse files Browse the repository at this point in the history
After devel/boost-libs is updated to 1.81.0, build fails on -CURRENT
because of clang's assertion failure as following.

clang-linux.compile.c++ bin.v2/libs/url/build/clang-linux-16/release/link-static/pch-off/threading-multi/visibility-hidden/src.o

  "c++" -c -x c++ -fvisibility-inlines-hidden -m64 -pthread -O3 -Wall -fvisibility=hidden -Wno-inline -pipe -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing -DLIBICONV_PLUG -std=gnu++17 -pipe -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing -DBOOST_ALL_NO_LIB=1 -DBOOST_URL_SOURCE -DBOOST_URL_STATIC_LINK=1 -DNDEBUG -I"."   -o "bin.v2/libs/url/build/clang-linux-16/release/link-static/pch-off/threading-multi/visibility-hidden/src.o" "libs/url/src/src.cpp"

Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /usr/src/contrib/llvm-project/llvm/include/llvm/Support/Casting.h, line 579.
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: c++ -c -x c++ -fvisibility-inlines-hidden -m64 -pthread -O3 -Wall -fvisibility=hidden -Wno-inline -pipe -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing -DLIBICONV_PLUG -std=gnu++17 -pipe -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing -DBOOST_ALL_NO_LIB=1 -DBOOST_URL_SOURCE -DBOOST_URL_STATIC_LINK=1 -DNDEBUG -I. -o bin.v2/libs/url/build/clang-linux-16/release/link-static/pch-off/threading-multi/visibility-hidden/src.o libs/url/src/src.cpp
1.	./boost/url/impl/segments_view.ipp:33:1: current parser token '{'
2.	./boost/url/impl/segments_view.ipp:17:1: parsing namespace 'boost'
3.	./boost/url/impl/segments_view.ipp:18:1: parsing namespace 'boost::urls'
 #0 0x00000000058158c1 PrintStackTrace /usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:567:13
 freebsd#1 0x0000000005813c45 RunSignalHandlers /usr/src/contrib/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 freebsd#2 0x00000000057bb7cb HandleCrash /usr/src/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 freebsd#3 0x00000000057bb7cb CrashRecoverySignalHandler /usr/src/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
 freebsd#4 0x000000082a4a9a8f handle_signal /usr/src/lib/libthr/thread/thr_sig.c:0:3
 freebsd#5 0x000000082a4a904b thr_sighandler /usr/src/lib/libthr/thread/thr_sig.c:247:1
 freebsd#6 0x000000082802a2d3 ([vdso]+0x2d3)
 freebsd#7 0x000000082e2a3cda thr_kill /usr/obj/usr/src/amd64.amd64/lib/libc/thr_kill.S:4:0
 freebsd#8 0x000000082e21d1f4 raise /usr/src/lib/libc/gen/raise.c:0:10
 freebsd#9 0x000000082e2cd3b9 abort /usr/src/lib/libc/stdlib/abort.c:73:17
c++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin
c++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
c++: note: diagnostic msg: /tmp/src-00f4ba.cpp
c++: note: diagnostic msg: /tmp/src-00f4ba.sh
c++: note: diagnostic msg:

********************
...failed clang-linux.compile.c++ bin.v2/libs/url/build/clang-linux-16/release/link-static/pch-off/threading-multi/visibility-hidden/src.o...

So add upstream patch to fix it.

PR:		269067
Obtained from:	https://reviews.llvm.org/D148474
  • Loading branch information
Yasuhiro Kimura committed Jan 6, 2024
1 parent aa1223a commit eae0e32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
51 changes: 25 additions & 26 deletions contrib/llvm-project/clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4092,16 +4092,13 @@ static bool hasCopyOrMoveCtorParam(ASTContext &Ctx,
return Ctx.hasSameUnqualifiedType(ParmT, ClassT);
}

static OverloadingResult
ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
MultiExprArg Args,
OverloadCandidateSet &CandidateSet,
QualType DestType,
DeclContext::lookup_result Ctors,
OverloadCandidateSet::iterator &Best,
bool CopyInitializing, bool AllowExplicit,
bool OnlyListConstructors, bool IsListInit,
bool SecondStepOfCopyInit = false) {
static OverloadingResult ResolveConstructorOverload(
Sema &S, SourceLocation DeclLoc, MultiExprArg Args,
OverloadCandidateSet &CandidateSet, QualType DestType,
DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator &Best,
bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors,
bool IsListInit, bool RequireActualConstructor,
bool SecondStepOfCopyInit = false) {
CandidateSet.clear(OverloadCandidateSet::CSK_InitByConstructor);
CandidateSet.setDestAS(DestType.getQualifiers().getAddressSpace());

Expand Down Expand Up @@ -4164,7 +4161,7 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
// Note: SecondStepOfCopyInit is only ever true in this case when
// evaluating whether to produce a C++98 compatibility warning.
if (S.getLangOpts().CPlusPlus17 && Args.size() == 1 &&
!SecondStepOfCopyInit) {
!RequireActualConstructor && !SecondStepOfCopyInit) {
Expr *Initializer = Args[0];
auto *SourceRD = Initializer->getType()->getAsCXXRecordDecl();
if (SourceRD && S.isCompleteType(DeclLoc, Initializer->getType())) {
Expand Down Expand Up @@ -4232,6 +4229,12 @@ static void TryConstructorInitialization(Sema &S,
return;
}

bool RequireActualConstructor =
!(Entity.getKind() != InitializedEntity::EK_Base &&
Entity.getKind() != InitializedEntity::EK_Delegating &&
Entity.getKind() !=
InitializedEntity::EK_LambdaToBlockConversionBlockElement);

// C++17 [dcl.init]p17:
// - If the initializer expression is a prvalue and the cv-unqualified
// version of the source type is the same class as the class of the
Expand All @@ -4241,11 +4244,7 @@ static void TryConstructorInitialization(Sema &S,
// class or delegating to another constructor from a mem-initializer.
// ObjC++: Lambda captured by the block in the lambda to block conversion
// should avoid copy elision.
if (S.getLangOpts().CPlusPlus17 &&
Entity.getKind() != InitializedEntity::EK_Base &&
Entity.getKind() != InitializedEntity::EK_Delegating &&
Entity.getKind() !=
InitializedEntity::EK_LambdaToBlockConversionBlockElement &&
if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) {
// Convert qualifications if necessary.
Expand Down Expand Up @@ -4293,11 +4292,10 @@ static void TryConstructorInitialization(Sema &S,
// If the initializer list has no elements and T has a default constructor,
// the first phase is omitted.
if (!(UnwrappedArgs.empty() && S.LookupDefaultConstructor(DestRecordDecl)))
Result = ResolveConstructorOverload(S, Kind.getLocation(), Args,
CandidateSet, DestType, Ctors, Best,
CopyInitialization, AllowExplicit,
/*OnlyListConstructors=*/true,
IsListInit);
Result = ResolveConstructorOverload(
S, Kind.getLocation(), Args, CandidateSet, DestType, Ctors, Best,
CopyInitialization, AllowExplicit,
/*OnlyListConstructors=*/true, IsListInit, RequireActualConstructor);
}

// C++11 [over.match.list]p1:
Expand All @@ -4307,11 +4305,10 @@ static void TryConstructorInitialization(Sema &S,
// elements of the initializer list.
if (Result == OR_No_Viable_Function) {
AsInitializerList = false;
Result = ResolveConstructorOverload(S, Kind.getLocation(), UnwrappedArgs,
CandidateSet, DestType, Ctors, Best,
CopyInitialization, AllowExplicit,
/*OnlyListConstructors=*/false,
IsListInit);
Result = ResolveConstructorOverload(
S, Kind.getLocation(), UnwrappedArgs, CandidateSet, DestType, Ctors,
Best, CopyInitialization, AllowExplicit,
/*OnlyListConstructors=*/false, IsListInit, RequireActualConstructor);
}
if (Result) {
Sequence.SetOverloadFailure(
Expand Down Expand Up @@ -6776,6 +6773,7 @@ static ExprResult CopyObject(Sema &S,
S, Loc, CurInitExpr, CandidateSet, T, Ctors, Best,
/*CopyInitializing=*/false, /*AllowExplicit=*/true,
/*OnlyListConstructors=*/false, /*IsListInit=*/false,
/*RequireActualConstructor=*/false,
/*SecondStepOfCopyInit=*/true)) {
case OR_Success:
break;
Expand Down Expand Up @@ -6921,6 +6919,7 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
S, Loc, CurInitExpr, CandidateSet, CurInitExpr->getType(), Ctors, Best,
/*CopyInitializing=*/false, /*AllowExplicit=*/true,
/*OnlyListConstructors=*/false, /*IsListInit=*/false,
/*RequireActualConstructor=*/false,
/*SecondStepOfCopyInit=*/true);

PartialDiagnostic Diag = S.PDiag(diag::warn_cxx98_compat_temp_copy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,10 @@ void Sema::PrintInstantiationStack() {
Diags.Report(Active->PointOfInstantiation,
diag::note_template_nsdmi_here)
<< FD << Active->InstantiationRange;
} else if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(D)) {
Diags.Report(Active->PointOfInstantiation,
diag::note_template_class_instantiation_here)
<< CTD << Active->InstantiationRange;
} else {
Diags.Report(Active->PointOfInstantiation,
diag::note_template_type_alias_instantiation_here)
Expand Down

0 comments on commit eae0e32

Please sign in to comment.