This is an archive of the discontinued LLVM Phabricator instance.

[libc++] [P1032] Finish constexpr-ifying <iterator>, <string_view>, <tuple>, <utility>.
ClosedPublic

Authored by Quuxplusone on Feb 9 2021, 4:46 PM.

Details

Summary

This completes the implementation of P1032's changes to <iterator>,
<string_view>, <tuple>, and <utility> in C++20.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1032r1.html

Drive-by fix a couple of unintended rvalues in "*iterators*/*.fail.cpp".

Diff Detail

Event Timeline

Quuxplusone created this revision.Feb 9 2021, 4:46 PM
Quuxplusone requested review of this revision.Feb 9 2021, 4:46 PM
Herald added a reviewer: Restricted Project. · View Herald TranscriptFeb 9 2021, 4:46 PM
ldionne requested changes to this revision.Feb 10 2021, 8:15 AM

Confirmed with Arthur that we're still missing some constexpr-ification in tuple, so we shouldn't mark the paper as implemented here. However, how about we add the missing constexprification in tuple in this patch?

Also, this is missing constexpr tests for all the iterators. We should write a dummy constexpr container to test those.

This revision now requires changes to proceed.Feb 10 2021, 8:15 AM

Oops, remove the change to libcxx/docs/Cxx2aStatusPaperStatus.csv — there are still plenty of parts to P1032 besides the iterator parts.

Quuxplusone edited the summary of this revision. (Show Details)

Finish implementing P1032 so we can really mark it "complete."
Lacks tests for constexpr pair and tuple.
Lacks tests for constexpr predef.iterators.

Quuxplusone retitled this revision from [libc++] [P1032] Misc constexpr bits in <iterator> to [libc++] [P1032] Finish constexpr-ifying <iterator>, <string_view>, <tuple>, <utility>..Feb 10 2021, 12:44 PM

Oops, update the feature-test macros for the newly added stuff.

Tangentially, @ldionne, I believe that the feature-test macro for
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1006r1.pdf (that's your own paper!)
i.e. __cpp_lib_constexpr_memory = 201811 should also be defined at this point. Could you confirm that and either commit it or ask me to commit it? :)

New constexpr tests for insert iterators.

Quuxplusone edited the summary of this revision. (Show Details)Feb 10 2021, 3:38 PM
ldionne requested changes to this revision.Feb 15 2021, 12:35 PM

Thanks for the heads up about __cpp_lib_constexpr_memory, fixed in 5d0d465ad4d25398519b85879d61fc126abd641c.

This is great, it's only missing some more tests. I don't foresee any additional issues given the appropriate tests.

libcxx/include/chrono
2311 ↗(On Diff #322846)

Those changes are orthogonal to the patch, could you please remove them (and commit them separately without review if you want, I don't mind).

This revision now requires changes to proceed.Feb 15 2021, 12:35 PM
Quuxplusone marked an inline comment as done.Feb 15 2021, 1:14 PM

Split out and merge the <chrono> cleanup. Rebase on main. void __swallow can't be constexpr before C++14.

ldionne requested changes to this revision.Feb 25 2021, 10:24 AM

I think this is great, but it needs to pass tests on GCC. It also probably needs rebasing onto main now. And all the things we're making constexpr should have their tests moved to check constexpr-friendliness too.

Requesting changes so it shows up right in the queue.

This revision now requires changes to proceed.Feb 25 2021, 10:24 AM

Rebased on main. (Looks like it rebased cleanly.) I don't remember why buildkite was unhappy before; let's see if it's happy this week.

Quuxplusone edited the summary of this revision. (Show Details)Mar 12 2021, 8:51 PM
Quuxplusone edited the summary of this revision. (Show Details)

Unsupport the failing string_view test on GCC (ostensibly until they get __builtin_strlen working, or until libc++ chooses to stop using it in char_traits).

libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
90

I've figured out that line 85 fails on GCC because libc++'s char_traits<char>::length calls __builtin_strlen, which is not a constant expression on GCC yet. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816

GNU libstdc++ works around this GCC bug by saying "okay, past C++17 we won't use __builtin_strlen anymore." See
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/char_traits.h#L364-L372

Should libc++ copy their cop-out (conditional on !defined(__clang__))? Or should I just mark this test as UNSUPPORTED: gcc-10 and move on? For now I'll upload a diff marked UNSUPPORTED just to prove that that'll make buildkite happy enough to land this if that's the route we want to take.

A few small comments now. More later (probably).

libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
59

Too bad we can't test this in a constexpr context 😔

83

Nit: might make sense to either name these a, g, and b or all abcde, ghijk, bcdjk.

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp
99

Mind adding a comment "Cannot be constexpr because of std::string" or something like that?

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp
129

Why not put this all in test?

129

Actually, it looks like CountAssign cant' be constexpr because of its global static vars.

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp
44

We're losing test coverage of constexpr between 11 and 20.

Quuxplusone marked 5 inline comments as done.

Address @zoecarver's initial review feedback.

ldionne requested changes to this revision.Mar 23 2021, 11:03 AM

This looks pretty good, but it seems that you included some changes that were not strictly added in P1032 in this patch too (eg some tests for tuple being constexpr). I'm fine with that, but I'd like to confirm that this was intentional.

libcxx/include/version
340

Why is this changing?

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp
14

Isn't that constexpr since C++14?

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
16

Same, this is constexpr since C++14?

This revision now requires changes to proceed.Mar 23 2021, 11:03 AM
Quuxplusone marked 4 inline comments as done.Mar 23 2021, 11:22 AM
Quuxplusone added inline comments.
libcxx/include/version
340

Fallout from D97904. I'll re-upload.

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp
14

make_tuple is; but the test case I'm modifying here also uses std::ref, which is constexpr in C++20 only.

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
16

Yes, but res = std::make_tuple(101, nullptr, -1.0); on line 38 is constexpr only in C++20 because operator=.

Quuxplusone marked 3 inline comments as done.

Re-upload with new and excitingly different spurious diffs in the autogenerated tests. 😛

libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
9–11

@ldionne, any thoughts on this bit?

ldionne added inline comments.Mar 24 2021, 5:23 AM
libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
9–11

I think this is reasonable. I think I'd rather wait for GCC to make their __builtin_strlen constexpr than add a GCC specific workaround for that in the library.

We could make it XFAIL so we're notified (by an XPASS) once GCC makes it constexpr.

ldionne accepted this revision.Mar 25 2021, 6:25 AM

LGTM with UNSUPPORTED => XFAIL for the gcc test.

This revision is now accepted and ready to land.Mar 25 2021, 6:25 AM

Hi,

I noticed that the following test failed with this patch:

Failed Tests (1):
  libc++ :: std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp

It hits an assertion:

clang-13: /repo/uabelho/master-github/clang/lib/AST/ExprConstant.cpp:5947: bool HandleUnionActiveMemberChange((anonymous namespace)::EvalInfo &, const clang::Expr *, const (anonymous namespace)::LValue &): Assertion `declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(), LHS.Designator.Entries[PathLength] .getAsBaseOrMember().getPointer())' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name convert_copy.pass.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -v -fcoverage-compilation-dir=/repo/uabelho/master-github/llvm/build-all-builtins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign -nostdinc++ -resource-dir /repo/uabelho/master-github/llvm/build-all-builtins/lib/clang/13.0.0 -include /repo/uabelho/master-github/llvm/build-all-builtins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/libcxx/__config_site -include /repo/uabelho/master-github/libcxx/test/support/nasty_macros.h -I /repo/uabelho/master-github/libcxx/include -I /repo/uabelho/master-github/llvm/build-all-builtins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/libcxx/include/c++build -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -I /repo/uabelho/master-github/libcxx/test/support -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D _LIBCPP_DISABLE_AVAILABILITY -D _LIBCPP_HAS_THREAD_API_PTHREAD -D _LIBCPP_ABI_VERSION=1 -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/include -internal-isystem /repo/uabelho/master-github/llvm/build-all-builtins/lib/clang/13.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror -Wall -Wextra -Wshadow -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Werror=thread-safety -Wuser-defined-warnings -Wno-macro-redefined -Wno-macro-redefined -std=c++2b -fdeprecated-macro -fdebug-compilation-dir=/repo/uabelho/master-github/llvm/build-all-builtins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign -ferror-limit 19 -fcoroutines-ts -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/convert_copy-5d8b65.o -x c++ /repo/uabelho/master-github/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp
1.	/repo/uabelho/master-github/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp:111:5: current parser token '{'
2.	/repo/uabelho/master-github/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp:105:1: parsing function body 'main'
3.	/repo/uabelho/master-github/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp:105:1: in compound statement ('{}')
 #0 0x0000000002ada0f3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x2ada0f3)
 #1 0x0000000002ad7dae llvm::sys::RunSignalHandlers() (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x2ad7dae)
 #2 0x0000000002ada5b6 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f8fa58f7630 __restore_rt sigaction.c:0:0
 #4 0x00007f8fa302a387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f8fa302ba78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007f8fa30231a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007f8fa3023252 (/lib64/libc.so.6+0x2f252)
 #8 0x000000000509b722 HandleUnionActiveMemberChange((anonymous namespace)::EvalInfo&, clang::Expr const*, (anonymous namespace)::LValue const&) ExprConstant.cpp:0:0
 #9 0x0000000005092a9e HandleFunctionCall(clang::SourceLocation, clang::FunctionDecl const*, (anonymous namespace)::LValue const*, llvm::ArrayRef<clang::Expr const*>, (anonymous namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#10 0x0000000005099c04 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::LValueExprEvaluator>::VisitCallExpr(clang::CallExpr const*) ExprConstant.cpp:0:0
#11 0x000000000508b200 EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#12 0x0000000005090aca Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#13 0x0000000005117d34 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::VoidExprEvaluator>::VisitBinaryOperator(clang::BinaryOperator const*) ExprConstant.cpp:0:0
#14 0x00000000050918b3 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#15 0x0000000005095631 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#16 0x000000000508b200 EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#17 0x0000000005090aca Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#18 0x000000000508c907 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) ExprConstant.cpp:0:0
#19 0x000000000509081e EvaluateCallArg(clang::ParmVarDecl const*, clang::Expr const*, (anonymous namespace)::CallRef, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#20 0x00000000050afe7f EvaluateArgs(llvm::ArrayRef<clang::Expr const*>, (anonymous namespace)::CallRef, (anonymous namespace)::EvalInfo&, clang::FunctionDecl const*, bool) ExprConstant.cpp:0:0
#21 0x0000000005118ca5 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::VoidExprEvaluator>::handleCallExpr(clang::CallExpr const*, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#22 0x0000000005115769 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::VoidExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#23 0x000000000511619b clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::VoidExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#24 0x00000000050918b3 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#25 0x00000000050b4fd7 EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) ExprConstant.cpp:0:0
#26 0x00000000050b550a EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) ExprConstant.cpp:0:0
#27 0x000000000509289e HandleFunctionCall(clang::SourceLocation, clang::FunctionDecl const*, (anonymous namespace)::LValue const*, llvm::ArrayRef<clang::Expr const*>, (anonymous namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#28 0x00000000051192d7 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::VoidExprEvaluator>::handleCallExpr(clang::CallExpr const*, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#29 0x0000000005115769 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::VoidExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#30 0x00000000050918b3 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#31 0x00000000050b4fd7 EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) ExprConstant.cpp:0:0
#32 0x00000000050b550a EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) ExprConstant.cpp:0:0
#33 0x000000000509289e HandleFunctionCall(clang::SourceLocation, clang::FunctionDecl const*, (anonymous namespace)::LValue const*, llvm::ArrayRef<clang::Expr const*>, (anonymous namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#34 0x0000000005099c04 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::LValueExprEvaluator>::VisitCallExpr(clang::CallExpr const*) ExprConstant.cpp:0:0
#35 0x000000000508b200 EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#36 0x0000000005090aca Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#37 0x00000000050b4fd7 EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) ExprConstant.cpp:0:0
#38 0x00000000050b550a EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) ExprConstant.cpp:0:0
#39 0x00000000050b550a EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) ExprConstant.cpp:0:0
#40 0x000000000509289e HandleFunctionCall(clang::SourceLocation, clang::FunctionDecl const*, (anonymous namespace)::LValue const*, llvm::ArrayRef<clang::Expr const*>, (anonymous namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#41 0x00000000050eb527 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::IntExprEvaluator>::handleCallExpr(clang::CallExpr const*, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#42 0x00000000050c38b8 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#43 0x0000000005090ca8 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#44 0x000000000508e130 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#45 0x000000000508a2ce clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, clang::ASTContext const&, bool) const (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x508a2ce)
#46 0x00000000047ebcb2 clang::Sema::VerifyIntegerConstantExpression(clang::Expr*, llvm::APSInt*, clang::Sema::VerifyICEDiagnoser&, clang::Sema::AllowFoldKind) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x47ebcb2)
#47 0x00000000047e9675 clang::Sema::VerifyIntegerConstantExpression(clang::Expr*, llvm::APSInt*, unsigned int, clang::Sema::AllowFoldKind) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x47e9675)
#48 0x00000000047361a9 clang::Sema::BuildStaticAssertDeclaration(clang::SourceLocation, clang::Expr*, clang::StringLiteral*, clang::SourceLocation, bool) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x47361a9)
#49 0x0000000004475bf8 clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x4475bf8)
#50 0x0000000004453815 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x4453815)
#51 0x00000000044f4fbd clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x44f4fbd)
#52 0x00000000044f3f41 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x44f3f41)
#53 0x00000000044fde01 clang::Parser::ParseCompoundStatementBody(bool) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x44fde01)
#54 0x00000000044ff055 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x44ff055)
#55 0x0000000004439efd clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x4439efd)
#56 0x000000000445a096 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x445a096)
#57 0x0000000004439095 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x4439095)
#58 0x0000000004438af5 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x4438af5)
#59 0x00000000044379d6 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x44379d6)
#60 0x000000000443578d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x443578d)
#61 0x000000000442fd48 clang::ParseAST(clang::Sema&, bool, bool) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x442fd48)
#62 0x00000000033796f3 clang::FrontendAction::Execute() (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x33796f3)
#63 0x00000000032f0474 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x32f0474)
#64 0x000000000342aad1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x342aad1)
#65 0x00000000009de555 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x9de555)
#66 0x00000000009dc991 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#67 0x00000000009dc44c main (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x9dc44c)
#68 0x00007f8fa3016555 __libc_start_main (/lib64/libc.so.6+0x22555)
#69 0x00000000009d93bd _start (/repo/uabelho/master-github/llvm/build-all-builtins/bin/clang-13+0x9d93bd)
clang-13: error: unable to execute command: Aborted
clang-13: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 13.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix

Hi,

I noticed that the following test failed with this patch:

Failed Tests (1):
  libc++ :: std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp

It hits an assertion:

clang-13: /repo/uabelho/master-github/clang/lib/AST/ExprConstant.cpp:5947: bool HandleUnionActiveMemberChange((anonymous namespace)::EvalInfo &, const clang::Expr *, const (anonymous namespace)::LValue &): Assertion `declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(), LHS.Designator.Entries[PathLength] .getAsBaseOrMember().getPointer())' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.

Hi @uabelho, could you file a bug report against Clang on https://bugs.llvm.org/ ? If you have the ability to reduce the test case using creduce, that would be awesome.
https://bugs.llvm.org/show_bug.cgi?id=45879 seems related but not identical (because the assertion that fails in that case is different).

Hi @Quuxplusone,

the same assert happens on the ARM cross toolchain builders:

FAIL: libc++::convert_copy.pass.cpp
Assertion failed: declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(), LHS.Designator.Entries[PathLength] .getAsBaseOrMember().getPointer()), file C:\buildbot\as-builder-1\x-armv7l\llvm-project\clang\lib\AST\ExprConstant.cpp, line 5947
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: C:\\buildbot\\as-builder-1\\x-armv7l\\build\\bin\\clang++.exe -cc1 -triple armv7-unknown-linux-gnueabihf -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name convert_copy.pass.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-abi aapcs-linux -mfloat-abi hard -fallow-half-arguments-and-returns -debugger-tuning=gdb -v -fcoverage-compilation-dir=C:\\buildbot\\as-builder-1\\x-armv7l\\build\\runtimes\\runtimes-bins\\libcxx\\test\\std\\utilities\\tuple\\tuple.tuple\\tuple.assign -nostdinc++ -resource-dir C:\\buildbot\\as-builder-1\\x-armv7l\\build\\lib\\clang\\13.0.0 -include C:/buildbot/as-builder-1/x-armv7l/build/runtimes/runtimes-bins/libcxx\\__config_site -include C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx\\test\\support\\nasty_macros.h -I C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx\\include -I C:/buildbot/as-builder-1/x-armv7l/build/runtimes/runtimes-bins/libcxx\\include\\c++build -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -I C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx\\test/support -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D _LIBCPP_DISABLE_AVAILABILITY -D _LIBCPP_HAS_THREAD_API_PTHREAD -D _LIBCPP_ABI_VERSION=1 -isysroot C:/buildbot/.arm-ubuntu -internal-isystem C:/buildbot/.arm-ubuntu/usr/local/include -internal-isystem C:/buildbot/.arm-ubuntu/usr/lib/gcc/arm-linux-gnueabihf/5.4.0/../../../../arm-linux-gnueabihf/include -internal-isystem C:\\buildbot\\as-builder-1\\x-armv7l\\build\\lib\\clang\\13.0.0\\include -internal-externc-isystem C:/buildbot/.arm-ubuntu/usr/include/arm-linux-gnueabihf -internal-externc-isystem C:/buildbot/.arm-ubuntu/include -internal-externc-isystem C:/buildbot/.arm-ubuntu/usr/include -Werror -Wall -Wextra -Wshadow -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Werror=thread-safety -Wuser-defined-warnings -Wno-macro-redefined -Wno-macro-redefined -std=c++2b -fdeprecated-macro -fdebug-compilation-dir=C:\\buildbot\\as-builder-1\\x-armv7l\\build\\runtimes\\runtimes-bins\\libcxx\\test\\std\\utilities\\tuple\\tuple.tuple\\tuple.assign -ferror-limit 19 -fcoroutines-ts -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o C:\\Users\\buildbot\\AppData\\Local\\Temp\\convert_copy-f069d8.o -x c++ C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp
1.	C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp:111:5: current parser token '{'
2.	C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp:105:1: parsing function body 'main'
3.	C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp:105:1: in compound statement ('{}')
...
...

Hi @vvereschaka, I've been working on reducing the Clang bug using creduce, but I made the mistake of not checking the exact assertion message in the interestingness check, and apparently assertion failures in debug mode are a dime a dozen. :) I've filed https://bugs.llvm.org/show_bug.cgi?id=49734 so far, and may file more if I can convince creduce to show me where they are.

The specific bug being triggered here is definitely https://bugs.llvm.org/show_bug.cgi?id=45879 , and I have just added a comment over there. Unfortunately it seems to have existed since May of last year, so a "quick fix" might not be likely. This seems like a no-win situation:

  • libc++ is supposed to work on Clang version X.Y
  • libc++ is also supposed to support C++20 constexpr tuple
  • constexpr tuple crashes Clang version X.Y (for now)
  • I don't think we're able to completely change how we implement tuple in order to work around the bug

@ldionne, what do you think? I'm thinking either "revert until we have a fix" — but that could be forever, there doesn't seem like any good option here — or "just UNSUPPORTED: this one test."
Is there an annotation like "UNSUPPORTED: clang-trunk"? 😛 Or if there's a way for #ifdef to tell that the compiler is Clang compiled in debug mode, that would be even cooler; we could skip just the failing part of the test, just in debug mode.

bjope added a subscriber: bjope.Mar 27 2021, 3:28 PM

Hi @Quuxplusone, understood, thank you! I agree with you that temporary disabling of the test for some configurations would be optimal for now.

There is no clang-trunk LIT feature currently, but probably UNSUPPORTED: clang-13 will help.

Or if there's a way for #ifdef to tell that the compiler is Clang compiled in debug mode,

There is nothing like that as far as I know.

What do you think about doing something about the failing test?

If you think this patch makes the testcase just trigger already existing bugs then disable the testcase so the bot goes back to green?

Thanks for your investigations Arthur, and sorry for missing your previous @ on March 26th.

I think marking the test as unsupported is fine as a temporary solution to keep the bots green, which is the #1 priority.

However, this is going to start failing again next release, and so on, until we fix the underlying bug, so I think we should either work on a libc++ workaround to stop triggering the bug, or on fixing the actual Clang issue.

ldionne added inline comments.May 28 2021, 5:38 AM
libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/container.pass.cpp
1

@Quuxplusone You didn't constexpr-ify this test (the default constructor one) for back_insert_iterator. Can you please go back and make sure you didn't forget others?

ldionne added inline comments.May 28 2021, 5:40 AM
libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/container.pass.cpp
1

Ugh, I mean the constexpr explicit back_insert_iterator(Container&) constructor, not the default constructor.

Also, it would be great to tidy this up at the top of the test files:

// explicit front_insert_iterator(Cont& x);

should become

// explicit front_insert_iterator(Cont& x); // constexpr in C++20