LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1234 - Build of ADT/SmallPtrSet fails
Summary: Build of ADT/SmallPtrSet fails
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Support Libraries (show other bugs)
Version: 1.0
Hardware: Macintosh MacOS X
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: build-problem
Depends on:
Blocks:
 
Reported: 2007-03-01 12:52 PST by aeriksson
Modified: 2010-02-22 12:53 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aeriksson 2007-03-01 12:52:06 PST
Building CVS HEAD on MacOSX fails with the following error:

$ make
make[1]: Nothing to be done for `all'.
llvm[1]: Compiling SmallPtrSet.cpp for Debug build 
/Users/andreas/build/llvmHEAD/llvm/include/llvm/ADT/SmallPtrSet.h:191: error: non-constant ‘((N | 
(N - 1)) + 1)’ cannot be used as template argument
/Users/andreas/build/llvmHEAD/llvm/include/llvm/ADT/SmallPtrSet.h:191: error: ‘Val’ is not a 
member of ‘<declaration error>’
make[1]: *** [/Users/andreas/build/llvmHEAD/llvm/lib/Support/Debug/SmallPtrSet.o] Error 1
make: *** [all] Error 1
Comment 1 Reid Spencer 2007-03-01 13:05:53 PST
The code in question is this:

template<unsigned N>
struct NextPowerOfTwoH<N, false> {
  enum {
    // We could just use NextVal = N+1, but this converges faster.  N|(N-1) sets
    // the right-most zero bits to one all at once, e.g. 0b0011000 -> 0b0011111.
    NextVal = (N|(N-1)) + 1,
    Val = NextPowerOfTwo<NextVal>::Val
  };
};

It does look wrongish and stuff. Are we depending on a compiler feature here?
Comment 2 Chris Lattner 2007-03-01 13:22:19 PST
N certainly is a constant.  what version of G++ are you compiling with?
Comment 3 aeriksson 2007-03-02 02:30:23 PST
I use the default g++ that comes with MacOSX 10.4 (g++ 4.1?).  I don't have
access to that computer right now, but I'll check later today.  Can anyone else
reproduce this?

I think the compiler is wrong; I've extracted the NextPowerOfTwo stuff and
tested it with g++ 3.4 and 4.1 on linux, Visual C++ 2005, and Comeau C++, and it
all works.

Also, I don't think that it is the "(N|(N-1))+1" part that causes the problem
because I could compile small tests with similar constructs without any
problems.   I experimented a bit, and it seems that line 192 is needed to get
the error.

191:    NextVal = (N|(N-1)) + 1,
192:    Val = NextPowerOfTwo<NextVal>::Val

Maybe, it is the fact that NextPowerOfTwo<N>::Val is "forward declared" when
referenced at line 192 that confuses the compiler (although it shouldn't)?  

This is all from memory right now, but I'll post more detailed information later
today when I get access to my mac.
Comment 4 aeriksson 2007-03-02 11:02:12 PST
$ g++ --version
powerpc-apple-darwin8-g++-4.0.0 (GCC) 4.0.0 20041026 (Apple Computer, Inc. build 4061)

I've compiled the NextPowerOfTwo stuff seperately and if line 192 is changed from
"Val = NextPowerOfTwo<NextVal>::Val" into "Val = 1" compilation succeds. This seems to indicate that
line 192 triggers the error reported on line 191.

If line 192 is changed into "Val = NextPowerOfTwo<1>::Val" I get the following error for that line:

error: incomplete type ‘NextPowerOfTwo<1u>’ used in nested name specifier

There is no other error reported: nothing about N or line 191.
Comment 5 Chris Lattner 2007-03-02 11:33:48 PST
Does it work if you change it to:
    Val = NextPowerOfTwo<(N|(N-1)) + 1>::Val

?

-Chris
Comment 6 aeriksson 2007-03-02 11:54:05 PST
Yes, that works!
Comment 7 Chris Lattner 2007-03-02 12:18:10 PST
Okay, very strange compiler bug.  Easy enough to work around though:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070226/045400.html

Thanks!

BTW, I recommend downloading the latest Xcode from developer.apple.com, there are several issues with 
older versions.  See the Getting Started guide for details on specific broken ones.

-Chris