llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

EnteringContext approach to nested-name-specifiers interacts badly with pointers-to-members

Open llvmbot opened this issue 13 years ago • 18 comments

Bugzilla Link 15554
Version trunk
OS All
Attachments unreduced test case, preprocessed
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

Seen assertion failure in C++ front-end. This is is running my powerpc-darwin8 branch, but probably affects all.

% /Users/fang/local/src/LLVM-svn/gcc40-cmake-build/bin/clang++ -DHAVE_CONFIG_H -I. -I../../bj-jedi-git/src -I/sw/include -O0 -MT bj/core/strategy.lo -MD -MP -MF bj/core/.deps/strategy.Tpo -c ../../bj-jedi-git/src/bj/core/strategy.cc -fno-common -DPIC -o bj/core/.libs/strategy.o -save-temps /Users/fang/local/src/LLVM-svn/llvm/tools/clang/lib/Sema/SemaTemplateDeduction.cpp:350: failed assertion `(Value->isTypeDependent() || Value->isValueDependent()) && "Expression template argument must be type- or value-dependent."' Stack dump: 0. Program arguments: /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1 -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name strategy.cc -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -coverage-file /Users/fang/local/src/bj-jedi/clang-build/src/strategy.s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -O0 -fdeprecated-macro -fdebug-compilation-dir /Users/fang/local/src/bj-jedi/clang-build/src -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o strategy.s -x c++-cpp-output strategy.ii

  1.  <eof> parser at end of file
    
  2.  /usr/include/c++/4.0.0/bits/stl_algobase.h:375:5: instantiating function definition 'copy'
    
  3.  /usr/include/c++/4.0.0/bits/stl_algobase.h:325:9: instantiating function definition 'copy_n'
    
  4.  /usr/include/c++/4.0.0/bits/stl_algobase.h:307:5: instantiating function definition '__copy_aux'
    
  5.  /usr/include/c++/4.0.0/bits/stl_algobase.h:280:9: instantiating function definition 'copy'
    

clang-3.1: error: unable to execute command: Abort trap clang-3.1: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.3 Target: powerpc-apple-darwin8.11.0 Thread model: posix clang-3.1: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang-3.1: note: diagnostic msg:


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


Will post a compressed-but-unreduced test case shortly.

llvmbot avatar Mar 20 '13 23:03 llvmbot

This is still broken: the testcase in comment#10 is still incorrectly rejected.

This seems to work on r192115! (tested on powerpc-darwin8) What revision fixed this, out of curiosity? (and was a test case added?)

llvmbot avatar Oct 08 '13 01:10 llvmbot

Ping? My reduced test case still fails in the same way, at r186828.

llvmbot avatar Jul 24 '13 22:07 llvmbot

Ping. Still fails on trunk. Any chance of this getting fixed in time for release 3.3?

llvmbot avatar Apr 17 '13 18:04 llvmbot

Much nastier case:

template<typename T> struct A;
template<typename T> struct A<T*> { static float A<T>::X::*p; };
template<typename T> float A<T>::X::*(A<T*>::p);

Here, we can't tell whether we're EnteringContext until after we've looked past the nested-name-specifier and seen that it's declaring a pointer-to-member. Perhaps when we are EnteringContext and we see a name component following a dependent-looking NNS, we could perform a tentative parse to see if there's a * after the NNS, or keep all subsequent name components as identifiers, and use RebuildNestedNameSpecifierInCurrentInstantiation to fix up afterwards.

If anyone cares, g++ 4.0.1, 4.4.7, 4.5.3, 4.6.3, 4.7.2 all compile these test cases fine.

llvmbot avatar Mar 25 '13 23:03 llvmbot

We have a rejects-valid on this, which is probably the same issue:

template<typename T> struct iterator_traits;

template <typename T> void f() {                                                 
  float iterator_traits<T>::value_type::*p = 0;  
}                             
<stdin>:4:29: error: no member named 'value_type' in 'iterator_traits<T>'
  float iterator_traits<T>::value_type::*p = 0;
        ~~~~~~~~~~~~~~~~~~~~^

We're probably performing a lookup into the dependent nested name specifier because we're parsing with EnteringContext = true.

error: /Users/fang/local/src/LLVM-svn/llvm/tools/clang/lib/Sema/SemaTemplateDeduction.cpp:350: failed assertion `(Value->isTypeDependent() || Value->isValueDependent()) && "Expression template argument must be type- or value-dependent."' Stack dump: 0. Program arguments: /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1 -cc1 -triple powerpc-apple-macosx10.4.0 -emit-obj -mrelax-all -disable-free -main-file-name strategy.ii -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -coverage-file /Users/fang/temp/clang/delta2/strategy.o -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -fdeprecated-macro -fdebug-compilation-dir /Users/fang/temp/clang/delta2 -ferror-limit 1 -fmessage-length 0 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -backend-option -vectorize-loops -o strategy.o -x c++-cpp-output strategy.ii

  1.  strategy.ii:23:14: current parser token ')'
    
  2.  strategy.ii:21:16: parsing function body 'main'
    
  3.  strategy.ii:21:16: in compound statement ('{}')
    

updated delta script: builddir=/Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build cxxflags="-ferror-limit=1"

make sure is valid C++

g++ -Wall -W -Werror -c strategy.ii -o strategy.o 2> /dev/null $builddir/bin/clang++ $cxxflags -o strategy.o -c strategy.ii 2>&1
| grep -q "failed assertion.*Expression template argument must be type- or value-dependent"

llvmbot avatar Mar 22 '13 02:03 llvmbot

more-reduced, still-valid:

template struct iterator_traits {
typedef typename _It::value_type value_type; }; template struct iterator_traits<_Tp*> {
typedef _Tp value_type; };

struct RS { float edge; };

template <typename _It, float iterator_traits<_It>::value_type::*> struct MSIter { typedef float value_type; MSIter(const _It); };

template <typename _It, float RS::*mem> int foo(const MSIter<_It, mem>&) { return 0; }

int main(void) { typedef MSIter<const RS*, &RS::edge> c_iter; const c_iter i(0); return foo(i); }

llvmbot avatar Mar 22 '13 02:03 llvmbot

more reduced and valid test case:

typedef long int ptrdiff_t; template struct iterator {
typedef _Tp value_type; }; template struct iterator_traits { typedef typename _It::value_type value_type; }; template struct iterator_traits<_Tp*> { typedef _Tp value_type; }; typedef double edge_type;

template struct array { typedef const T* const_iterator; const_iterator begin() const; const_iterator end() const; }; struct RS { edge_type edge; };

template <typename _It, typename T, T iterator_traits<_It>::value_type::*mem> struct MSIter : public iterator { typedef _It iterator_type; explicit MSIter(const iterator_type); };

template <typename _It, typename T, T iterator_traits<_It>::value_type::*mem> inline ptrdiff_t operator - (const MSIter<_It,T,mem>&, const MSIter<_It,T,mem>&) { return 0; }

int main(void) { typedef array array_type; array_type r; typedef MSIter<array_type::const_iterator, const edge_type, &RS::edge> c_iter; const c_iter i(r.begin()), e(r.end()); return e -i; }

llvmbot avatar Mar 22 '13 02:03 llvmbot

valid C++ test case this test case is valid C++, semi-reduced

llvmbot avatar Mar 21 '13 23:03 llvmbot

This was using r176996 on svn-trunk/git-master, which was merged into the powerpc-darwin8 branch.

I have delta crunching away at reducing this, but on a rather slow machine, so it may take several days...

delta script: #!/bin/sh -e builddir=/Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build $builddir/bin/clang++ -fno-common -O0 -DPIC -o strategy.o -c strategy.ii 2>&1
| grep -q "failed assertion.*Expression template argument must be type- or value-dependent"

llvmbot avatar Mar 21 '13 00:03 llvmbot

Reduced test case by the author appears to be fixed in Clang 3.4: https://godbolt.org/z/P5Tzj1ra9 The first test case by Richard appears to be fixed in Clang 3.4 as well: https://godbolt.org/z/oGnKohGar The second test case by Richard is still rejected by every implementation except for GCC: https://godbolt.org/z/aerEhjs97

Endilll avatar Jun 25 '23 15:06 Endilll

@llvm/issue-subscribers-clang-frontend

llvmbot avatar Jun 25 '23 15:06 llvmbot

The second test case by Richard is still rejected by every implementation except for GCC: https://godbolt.org/z/aerEhjs97

Clang trunk can now compile this code. CC @Endilll

MagentaTreehouse avatar Jan 14 '25 22:01 MagentaTreehouse

Fixed in both clang and gcc trunk: https://godbolt.org/z/4MoYxe1cr

although edg/MSVC still don't accept.

shafik avatar Jan 15 '25 01:01 shafik

Do we have tests for all these cases? This seems like the sort of thing that could easily regress.

zygoloid avatar Jan 16 '25 19:01 zygoloid