Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes with Type constraint should be initialized before we can access it #20

Closed
davidstone opened this issue Sep 8, 2019 · 1 comment

Comments

@davidstone
Copy link

template <typename T>
concept integer_constructible_from = basic_numeric_limits<T>::is_specialized and (std::is_enum_v<std::decay_t<T>>);

template <typename T>
constexpr auto is_convertible_to_range(auto const minimum) {
  using decayed = std::decay_t<T>;
  if constexpr (integer_constructible_from<T> and !std::is_same_v<decayed, bool>) {
    return compare(minimum, limits::min()) and compare(limits::max(), minimum);
  }
}

template <typename T, auto minimum>
concept convertible_to_range = is_convertible_to_range<T>(minimum);

type_overlaps_range<std::decay_t<T>>(0);

template <auto value, typename overflow_policy = null_policy>
using constant_t = integer<value, overflow_policy>;

template <auto minimum> struct integer {
  template <convertible_to_range<minimum> T>
  constexpr integer(T const other);
};

Sorry for the poor reduction on this one. The unreduced version doesn't have the compile errors and seems to be valid code.

This code crashes in an asserts enabled build with:

file.cpp:2:38: error: no template named 'basic_numeric_limits'
concept integer_constructible_from = basic_numeric_limits::is_specialized and (std::is_enum_v<std::decay_t>);
^
file.cpp:2:83: error: use of undeclared identifier 'std'
concept integer_constructible_from = basic_numeric_limits::is_specialized and (std::is_enum_v<std::decay_t>);
^
file.cpp:2:98: error: use of undeclared identifier 'std'
concept integer_constructible_from = basic_numeric_limits::is_specialized and (std::is_enum_v<std::decay_t>);
^
file.cpp:2:114: error: type name requires a specifier or qualifier
concept integer_constructible_from = basic_numeric_limits::is_specialized and (std::is_enum_v<std::decay_t>);
^
file.cpp:6:19: error: use of undeclared identifier 'std'
using decayed = std::decay_t;
^
file.cpp:6:19: error: expected a type
file.cpp:6:24: error: expected ';' after alias declaration
using decayed = std::decay_t;
^
;
file.cpp:7:52: error: use of undeclared identifier 'std'
if constexpr (integer_constructible_from and !std::is_same_v<decayed, bool>) {
^
file.cpp:7:67: error: use of undeclared identifier 'decayed'
if constexpr (integer_constructible_from and !std::is_same_v<decayed, bool>) {
^
file.cpp:7:17: error: use of undeclared identifier 'integer_constructible_from'
if constexpr (integer_constructible_from and !std::is_same_v<decayed, bool>) {
^
file.cpp:8:29: error: use of undeclared identifier 'limits'
return compare(minimum, limits::min()) and compare(limits::max(), minimum);
^
file.cpp:8:56: error: use of undeclared identifier 'limits'
return compare(minimum, limits::min()) and compare(limits::max(), minimum);
^
file.cpp:15:21: error: use of undeclared identifier 'std'
type_overlaps_range<std::decay_t>(0);
^
file.cpp:15:34: error: use of undeclared identifier 'T'
type_overlaps_range<std::decay_t>(0);
^
file.cpp:15:1: error: no template named 'type_overlaps_range'
type_overlaps_range<std::decay_t>(0);
^
file.cpp:15:21: error: use of undeclared identifier 'std'
type_overlaps_range<std::decay_t>(0);
^
file.cpp:15:34: error: use of undeclared identifier 'T'
type_overlaps_range<std::decay_t>(0);
^
file.cpp:15:40: error: expected a type
type_overlaps_range<std::decay_t>(0);
^
file.cpp:17:50: error: unknown type name 'null_policy'
template <auto value, typename overflow_policy = null_policy>
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Type constraint should be initialized before we can access it
UNREACHABLE executed at /home/david/llvm-concepts2/clang/include/clang/AST/DeclTemplate.h:1357!
Stack dump:
0. Program arguments: /home/david/llvm-concepts/build/bin/clang-10 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name file.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /dev/null.gcno -resource-dir /home/david/llvm-concepts/build/lib/clang/10.0.0 -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9 -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/x86_64-pc-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/backward -internal-isystem /usr/local/include -internal-isystem /home/david/llvm-concepts/build/lib/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++2a -fdeprecated-macro -fdebug-compilation-dir /home/david/tm/build-bi-clang-debug/reduce -ferror-limit 19 -fmessage-length 0 -fno-implicit-modules -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -fconcepts-ts -o /dev/null -x c++ file.cpp

  1. file.cpp:22:3: current parser token 'constexpr'
  2. file.cpp:20:25: parsing struct/union/class body 'integer'
    #0 0x000000000304006d PrintStackTraceSignalHandler(void*) (.llvm.5230716231219214910) (/home/david/llvm-concepts/build/bin/clang-10+0x304006d)
    Should not define __cpp_concepts #1 0x000000000303d7f0 llvm::sys::RunSignalHandlers() (/home/david/llvm-concepts/build/bin/clang-10+0x303d7f0)
    Cannot yet mangle expression type RequiresExpr #2 0x0000000003040508 SignalHandler(int) (/home/david/llvm-concepts/build/bin/clang-10+0x3040508)
    'std::initializer_list<bool>' is not a literal type?? #3 0x00007fdd7e2e5660 __restore_rt (/lib64/libpthread.so.0+0x14660)
    Please add flag -fconcepts #4 0x00007fdd7dcf6d21 raise (/lib64/libc.so.6+0x38d21)
    Friend declarations are not working? #5 0x00007fdd7dce0535 abort (/lib64/libc.so.6+0x22535)
    Parsing: Retry as expression instead when reaching open-brace at block-scope #6 0x0000000002fd7fae (/home/david/llvm-concepts/build/bin/clang-10+0x2fd7fae)
    Wrong declaration lookup when compiled with module support (-fmodules) #7 0x0000000005347340 clang::TemplateParameterList::TemplateParameterList(clang::ASTContext const&, clang::SourceLocation, clang::SourceLocation, llvm::ArrayRefclang::NamedDecl*, clang::SourceLocation, clang::Expr*, clang::TemplateParameterList*) (/home/david/llvm-concepts/build/bin/clang-10+0x5347340)
    Massive memory consumption to build relative simple classes #8 0x0000000004f0a064 clang::Sema::ActOnTemplateParameterList(unsigned int, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, llvm::ArrayRefclang::NamedDecl*, clang::SourceLocation, clang::Expr*) (/home/david/llvm-concepts/build/bin/clang-10+0x4f0a064)
    Redundant instantiation explanations #9 0x000000000487b712 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x487b712)
    Some tests failing when built -DLLVM_ENABLE_ASSERTIONS=yes #10 0x000000000486d881 clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject*) (/home/david/llvm-concepts/build/bin/clang-10+0x486d881)
    crash #11 0x0000000004870f01 clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&, clang::Parser::ParsedAttributesWithRange&, clang::TypeSpecifierType, clang::Decl*) (/home/david/llvm-concepts/build/bin/clang-10+0x4870f01)
    Cannot default auto function parameters #12 0x000000000486a1f6 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&, unsigned int, clang::Decl*) (/home/david/llvm-concepts/build/bin/clang-10+0x486a1f6)
    How to build it? #13 0x000000000486731e clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::Parser::ParsedAttributesWithRange&) (/home/david/llvm-concepts/build/bin/clang-10+0x486731e)
    gcc standard library starts to include concepts #14 0x000000000481eef9 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) (/home/david/llvm-concepts/build/bin/clang-10+0x481eef9)
    Constrained specialization of a template is rejected #15 0x000000000487c7ed clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x487c7ed)
    Dependent class member access not correctly treated as lvalue in requires-expression #16 0x000000000487b9a1 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x487b9a1)
    ICE parsing deduction guide for class template with constrained constructor #17 0x000000000487b220 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x487b220)
    Crash when explicitly qualifying namespace of concept when using void foo(thing auto) syntax #18 0x000000000481e180 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/home/david/llvm-concepts/build/bin/clang-10+0x481e180)
    Cannot constrain constructor with terse syntax if concept has explicit parameters #19 0x00000000047d7a94 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/home/david/llvm-concepts/build/bin/clang-10+0x47d7a94)
    Crashes with Type constraint should be initialized before we can access it #20 0x00000000047d61dd clang::Parser::ParseTopLevelDecl(clang::OpaquePtrclang::DeclGroupRef&, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x47d61dd)
    Assertion failure when constraining non-template member of class template #21 0x00000000047d16f4 clang::ParseAST(clang::Sema&, bool, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x47d16f4)
    Concept definitions with unexpanded variadic template parameters evaluate to true #22 0x000000000398080f clang::FrontendAction::Execute() (/home/david/llvm-concepts/build/bin/clang-10+0x398080f)
    Terse syntax does not work with noexcept clauses #23 0x00000000038df6a8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/david/llvm-concepts/build/bin/clang-10+0x38df6a8)
    Assertion failure with member access of result of function declared with decltype(expr) return type #24 0x0000000003a2b327 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/david/llvm-concepts/build/bin/clang-10+0x3a2b327)
    Concepts ignored in arguments to lambdas #25 0x0000000001fc93ee cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/david/llvm-concepts/build/bin/clang-10+0x1fc93ee)
    fail to compile for libstdc++ #26 0x0000000001fc7168 main (/home/david/llvm-concepts/build/bin/clang-10+0x1fc7168)
    Compiler ICE #27 0x00007fdd7dce1f1b __libc_start_main (/lib64/libc.so.6+0x23f1b)
    An auto parameter makes [[maybe_unused]] ignored on all parameters #28 0x0000000001fc402a _start (/home/david/llvm-concepts/build/bin/clang-10+0x1fc402a)
    clang-10: error: unable to execute command: Aborted (core dumped)
    clang-10: error: clang frontend command failed due to signal (use -v to see invocation)
    clang version 10.0.0 ([email protected]:saarraz/clang-concepts-monorepo.git 55730ed)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /home/david/llvm-concepts/build/bin
    clang-10: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
    clang-10: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-10: note: diagnostic msg: /tmp/file-95a46b.cpp
clang-10: note: diagnostic msg: /tmp/file-95a46b.sh
clang-10: note: diagnostic msg:


@davidstone
Copy link
Author

Resolved in latest commit

saarraz pushed a commit that referenced this issue Jan 23, 2020
This reverts commit e57a9ab.

Parser/cxx2a-placeholder-type-constraint.cpp has MSan failures.

Present at 7b81c3f:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan/builds/17133/steps/check-clang%20msan/logs/stdio
not present at eaa594f:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan/builds/17132/steps/check-clang%20msan/logs/stdio

Stack trace:
```
==57032==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0xccfe016 in clang::AutoTypeLoc::getLocalSourceRange() const /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/include/clang/AST/TypeLoc.h:2036:19
    #1 0xcc56758 in CheckDeducedPlaceholderConstraints(clang::Sema&, clang::AutoType const&, clang::AutoTypeLoc, clang::QualType) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Sema/SemaTemplateDeduction.cpp:4505:56
    #2 0xcc550ce in clang::Sema::DeduceAutoType(clang::TypeLoc, clang::Expr*&, clang::QualType&, llvm::Optional<unsigned int>, bool) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Sema/SemaTemplateDeduction.cpp:4707:11
    #3 0xcc52407 in clang::Sema::DeduceAutoType(clang::TypeSourceInfo*, clang::Expr*&, clang::QualType&, llvm::Optional<unsigned int>, bool) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Sema/SemaTemplateDeduction.cpp:4457:10
    #4 0xba38332 in clang::Sema::deduceVarTypeFromInitializer(clang::VarDecl*, clang::DeclarationName, clang::QualType, clang::TypeSourceInfo*, clang::SourceRange, bool, clang::Expr*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Sema/SemaDecl.cpp:11351:7
    #5 0xba3a8a9 in clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Sema/SemaDecl.cpp:11385:26
    #6 0xba3c520 in clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Sema/SemaDecl.cpp:11725:9
    #7 0xb39c498 in clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:2399:17
    #8 0xb394d80 in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:2128:21
    #9 0xb383bbf in clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:1848:10
    #10 0xb383129 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/include/llvm/ADT/PointerUnion.h
    #11 0xb53a388 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:221:13
    #12 0xb539309 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:106:20
    #13 0xb55610e in clang::Parser::ParseCompoundStatementBody(bool) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:1079:11
    #14 0xb559529 in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:2204:21
    #15 0xb33c13e in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/Parser.cpp:1339:10
    #16 0xb394703 in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:2068:11
    #17 0xb338e52 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/Parser.cpp:1099:10
    #18 0xb337674 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/Parser.cpp:1115:12
    #19 0xb334a96 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/Parser.cpp:935:12
    #20 0xb32f12a in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/Parser.cpp:686:12
    #21 0xb31e193 in clang::ParseAST(clang::Sema&, bool, bool) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Parse/ParseAST.cpp:158:20
    #22 0x80263f0 in clang::FrontendAction::Execute() /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Frontend/FrontendAction.cpp:936:8
    #23 0x7f2a257 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:965:33
    #24 0x8288bef in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:290:25
    #25 0xad44c2 in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/tools/driver/cc1_main.cpp:239:15
    #26 0xacd76a in ExecuteCC1Tool(llvm::ArrayRef<char const*>) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/tools/driver/driver.cpp:325:12
    #27 0xacc9fd in main /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/tools/driver/driver.cpp:398:12
    #28 0x7f7d82cdb2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #29 0xa4dde9 in _start (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang-11+0xa4dde9)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant