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 854 - llvm-gcc4: crash compiling constant expr cast
Summary: llvm-gcc4: crash compiling constant expr cast
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-gcc (show other bugs)
Version: 1.4
Hardware: All All
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2006-07-28 23:42 PDT by Nick Lewycky
Modified: 2010-02-22 12:43 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments
delta minimized testcase 18257.c (45.89 KB, text/plain)
2006-07-28 23:44 PDT, Nick Lewycky
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Lewycky 2006-07-28 23:42:58 PDT
I met an assertion failure in llvm-gcc while compiling the linux kernel.
Testcase attached in a second...
Comment 1 Nick Lewycky 2006-07-28 23:44:44 PDT
Created attachment 373 [details]
delta minimized testcase 18257.c

$ /usr/local/bin/llvm-gcc -Wp,-MD,$KERNEL/init/.main.o.d -Wall -Wundef
-Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Os
-fomit-frame-pointer -pipe -msoft-float -mpreferred-stack-boundary=2  -march=k8
-mregparm=3 -ffreestanding -Wdeclaration-after-statement -Wno-pointer-sign
bug.c -S -o bug.s

[...]

 <convert_expr 0x55bde0c8
    type <integer_type 0x55ac6528 int sizes-gimplified public SI
	size <integer_cst 0x55ac05e8 constant invariant 32>
	unit size <integer_cst 0x55ac0310 constant invariant 4>
	align 32 symtab 145604960 alias set -1 precision 32 min <integer_cst
0x55ac0594 -2147483648> max <integer_cst 0x55ac05b0 2147483647>
	pointer_to_this <pointer_type 0x55acfbb8>>
    constant invariant
    arg 0 <addr_expr 0x55bde0a0
	type <pointer_type 0x55b40d98 type <integer_type 0x55ac6690 long
unsigned int>
	    unsigned SI size <integer_cst 0x55ac05e8 32> unit size <integer_cst
0x55ac0310 4>
	    align 32 symtab 0 alias set -1>
	constant invariant
	arg 0 <var_decl 0x55bdd3c0 loops_per_jiffy type <integer_type
0x55ac6690 long unsigned int>
	    addressable used public static unsigned asm-frame-size 0 SI file
bug.c line 1431 size <integer_cst 0x55ac05e8 32> unit size <integer_cst
0x55ac0310 4>
	    align 32 initial <integer_cst 0x55bb355c 4096>>>>
cc1: ../../src/gcc/llvm-convert.cpp:3844: static llvm::Constant*
TreeConstantToLLVM::Convert(tree_node*): Assertion `0 && "Unknown constant to
convert!"' failed.
bug.c: At top level:
bug.c:1465: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://llvm.org/bugs> for instructions.
$
Comment 2 Nick Lewycky 2006-07-30 08:58:13 PDT
I've reduced the testcase by hand:

  struct kernel_symbol {
    unsigned long value;
  };
  unsigned long loops_per_jiffy = (1<<12);
  static const char __kstrtab_loops_per_jiffy[]
__attribute__((section("__ksymtab_strings"))) = "loops_per_jiffy";
  static const struct kernel_symbol __ksymtab_loops_per_jiffy
__attribute__((__used__)) __attribute__((section("__ksymtab"))) = { (unsigned
long)&loops_per_jiffy, __kstrtab_loops_per_jiffy };

This compiles with GCC 4.0 using "gcc bug.c -S -o bug.s", and the same command
causes llvm-gcc to ICE with the assertion.
Comment 3 Chris Lattner 2006-07-31 12:33:15 PDT
Fixed.  Testcase here: Regression/CFrontend/2006-07-31-PR854.c

Patch here:

Index: llvm-convert.cpp
===============================================================
====
--- llvm-convert.cpp    (revision 116626)
+++ llvm-convert.cpp    (working copy)
@@ -3852,6 +3852,7 @@ Constant *TreeConstantToLLVM::Convert(tr
   case STRING_CST:    return ConvertSTRING_CST(exp);
   case COMPLEX_CST:   return ConvertCOMPLEX_CST(exp);
   case NOP_EXPR:      return ConvertNOP_EXPR(exp);
+  case CONVERT_EXPR:  return ConvertCONVERT_EXPR(exp);
   case PLUS_EXPR:
   case MINUS_EXPR:    return ConvertBinOp_CST(exp);
   case CONSTRUCTOR:   return ConvertCONSTRUCTOR(exp);
@@ -3986,6 +3987,11 @@ Constant *TreeConstantToLLVM::ConvertNOP
   return ConstantExpr::getCast(Elt, ConvertType(TREE_TYPE(exp)));
 }
 
+Constant *TreeConstantToLLVM::ConvertCONVERT_EXPR(tree exp) {
+  Constant *Elt = Convert(TREE_OPERAND(exp, 0));
+  return ConstantExpr::getCast(Elt, ConvertType(TREE_TYPE(exp)));
+}
+
 Constant *TreeConstantToLLVM::ConvertBinOp_CST(tree exp) {
   Constant *LHS = Convert(TREE_OPERAND(exp, 0));
   Constant *RHS = Convert(TREE_OPERAND(exp, 1));
Index: llvm-internal.h
===============================================================
====
--- llvm-internal.h     (revision 116625)
+++ llvm-internal.h     (working copy)
@@ -470,6 +470,7 @@ public:
   static Constant *ConvertSTRING_CST(tree_node *exp);
   static Constant *ConvertCOMPLEX_CST(tree_node *exp);
   static Constant *ConvertNOP_EXPR(tree_node *exp);
+  static Constant *ConvertCONVERT_EXPR(tree_node *exp);
   static Constant *ConvertBinOp_CST(tree_node *exp);
   static Constant *ConvertCONSTRUCTOR(tree_node *exp);
   static Constant *ConvertArrayCONSTRUCTOR(tree_node *exp);