Skip to content

Incorrect source range for instantiations of out-of-line defaulted special member functions of class templates #26057

Closed
@cov-tprince

Description

@cov-tprince
Bugzilla Link 25683
Version 3.7
OS All
CC @synopsys-sig-compiler-frontends,@tahonermann

Extended Description

The following snippet produces an AST in which the starting source location appears after the end location:

$ cat bad.cpp
template struct s { s(); };
s a;
template s::s() = default;
$ clang -v -std=c++11 -Xclang -ast-dump -fsyntax-only bad.cpp
clang version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.3
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
"/opt/pkg/clang-3.7.0/bin/clang-3.7" -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -main-file-name bad.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -resource-dir /opt/pkg/clang-3.7.0/bin/../lib/clang/3.7.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward -internal-isystem /usr/local/include -internal-isystem /opt/pkg/clang-3.7.0/bin/../lib/clang/3.7.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /slowfs/sighome/trprince/lab/bz82561 -ferror-limit 19 -fmessage-length 211 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -ast-dump -x c++ bad.cpp
clang -cc1 version 3.7.0 based upon LLVM 3.7.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward
/usr/local/include
/opt/pkg/clang-3.7.0/bin/../lib/clang/3.7.0/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
TranslationUnitDecl 0x86c6510 <>
|-TypedefDecl 0x86c6a48 <> implicit __int128_t '__int128'
|-TypedefDecl 0x86c6aa8 <> implicit __uint128_t 'unsigned __int128'
|-TypedefDecl 0x86c6e88 <> implicit __builtin_va_list '__va_list_tag [1]'
|-ClassTemplateDecl 0x86c7020 <bad.cpp:1:1, col:37> col:28 s
| |-TemplateTypeParmDecl 0x86c6ed8 col:11 col:11 typename
| |-CXXRecordDecl 0x86c6f90 <col:21, col:37> col:28 struct s definition
| | |-CXXRecordDecl 0x870f060 <col:21, col:28> col:28 implicit referenced struct s
| | -CXXConstructorDecl 0x870f190 <col:32, col:34> col:32 s<type-parameter-0-0> 'void (void)' | -ClassTemplateSpecializationDecl 0x870f260 <col:1, col:37> col:28 struct s definition
| |-TemplateArgument type 'int'
| |-CXXRecordDecl 0x870f508 prev 0x870f260 <col:21, col:28> col:28 implicit struct s
| |-CXXConstructorDecl 0x870f5d8 <line:3:23, line:1:32> col:32 used constexpr s 'void (void) noexcept'
| | -CompoundStmt 0x870feb0 <col:32> | |-CXXConstructorDecl 0x870f6d8 <col:28> col:28 implicit constexpr s 'void (const struct s<int> &)' inline noexcept-unevaluated 0x870f6d8 | | -ParmVarDecl 0x870f820 col:28 col:28 'const struct s &'
| -CXXConstructorDecl 0x870f8b8 <col:28> col:28 implicit constexpr s 'void (struct s<int> &&)' inline noexcept-unevaluated 0x870f8b8 | -ParmVarDecl 0x870fa00 col:28 col:28 'struct s &&'
|-VarDecl 0x870f408 <line:2:1, col:8> col:8 a 's':'struct s' callinit
| -CXXConstructExpr 0x870fa68 <col:8> 's<int>':'struct s<int>' 'void (void) noexcept' -CXXConstructorDecl 0x870fd40 parent 0x86c6f90 prev 0x870f190 <line:3:1, col:31> col:29 s 'void (void)'
$

In particular, note the line numbers on the second CXXConstructorDecl:

CXXConstructorDecl 0x870f5d8 <line:3:23, line:1:32>

This doesn't seem to cause any problems in clang proper, but passing this range to clang::PreprocessingRecord::getPreprocessedEntitiesInRange triggers an assertion, since the start of the range occurs after the end.

Metadata

Metadata

Assignees

Labels

awaiting-reviewHas pending Phabricator reviewbugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions