llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.02k stars 11.96k forks source link

"Invalid GetElementPtrInst indices for type!" on valid structure #10265

Closed kripken closed 13 years ago

kripken commented 13 years ago
Bugzilla Link 9893
Resolution FIXED
Resolved on Oct 09, 2011 23:20
Version 2.9
OS Linux
CC @DougGregor,@rjmccall

Extended Description

The following code fails to compile with clang:

======

include "stdio.h"

struct usvec { int x; };

struct shaftbb { union { int v[2]; struct { usvec min, max; }; };

shaftbb() {} };

int main() { shaftbb s; return 1; }

The error is

====== clang: /home/alon/Dev/llvm-svn/include/llvm/Instructions.h:278: const llvm::Type llvm::checkType(const llvm::Type): Assertion `Ty && "Invalid GetElementPtrInst indices for type!"' failed. 0 clang 0x095746a8 Stack dump:

  1. Program arguments: /home/alon/Dev/llvm-svn/build/Release+Asserts/bin/clang -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name llvm1.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.20.1 -momit-leaf-frame-pointer -resource-dir /home/alon/Dev/llvm-svn/build/Release+Asserts/bin/../lib/clang/3.0 -ferror-limit 19 -fmessage-length 141 -fcxx-exceptions -fexceptions -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-ImS38f.o -x c++ llvm1.cpp
  2. parser at end of file
  3. Per-file LLVM IR generation
  4. llvm1.cpp:16:3: Generating code for declaration 'shaftbb::shaftbb' clang: error: unable to execute command: Aborted clang: error: clang frontend command failed due to signal 1 (use -v to see invocation)

The file compiles ok with gcc.

This is a reduced testcase from pvs.cpp from Sauerbraten (open source FPS) which I am trying to compile with clang.

DougGregor commented 13 years ago

This is fixed in top-of-tree.

lattner commented 13 years ago

Here's a reduced testcase:

struct usvec { int x; };

struct shaftbb { union { int v[2]; struct { usvec min, max; }; };

shaftbb(); };

shaftbb::shaftbb() {}

Clang is dying trying to get an lvalue to min to initialize it. This is probably a trivial bug (just insert a bitcast somewhere), but it's not clear to me why we're trying to do any initialization in the constructor in this case at all.