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 1083 - K&R C compilation failure
Summary: K&R C compilation failure
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-gcc (show other bugs)
Version: 1.9
Hardware: PC Linux
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2007-01-06 14:38 PST by Domagoj
Modified: 2018-11-07 00:17 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
delta-reduced testcase (577 bytes, text/plain)
2007-01-06 15:20 PST, Anton Korobeynikov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Domagoj 2007-01-06 14:38:38 PST
$:~/tmp$ llvm-gcc -emit-llvm -c svc.c -o svc.o
cc1: ../../dst-directory/gcc/llvm-convert.cpp:216:
void<unnamed>::FunctionPrologArgumentConversion::HandleScalarArgument(const
llvm::Type*): Assertion `ArgVal->getType()->isIntegral() && LLVMTy->isIntegral()
&& "Lowerings don't match?"' failed.
svc.c: In function ‘svc_register’:
svc.c:11: internal compiler error: Aborted
Please submit a full bug report,

Source: [svc.c from dietlib v0.30]
------------------------------------------------
#include <rpc/rpc.h>

static SVCXPRT **xports;

bool_t svc_register(xprt, prog, vers, dispatch, protocol)
SVCXPRT *xprt;
unsigned long prog;
unsigned long vers;
void (*dispatch) ();
rpcprot_t protocol;
{
	return (TRUE);
}
------------------------------------------------

Can be reproduced with:
llvm-gcc [-emit-llvm] -c svc.c -o svc.o

Domagoj
Comment 1 Domagoj 2007-01-06 15:10:16 PST
aKor has just pointed me to 
http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070104/5c2b9cf1/attachment.txt
suggesting that that patch is the most likely source of the problem.
However, I don't have that patch applied. So, with, or without the patch,
the code seems to be buggy.

To clear any possible confusion, here's my current code:
------------------------------------------------
    void HandleScalarArgument(const llvm::Type *LLVMTy) {
      Value *ArgVal = AI;
      if (ArgVal->getType() != LLVMTy) {
        // If this is just a mismatch between integer types, this could be due
        // to K&R prototypes, where the forward proto defines the arg as int and
        // the actual impls is a short or char.
        assert(ArgVal->getType()->isIntegral() && LLVMTy->isIntegral() &&
               "Lowerings don't match?");
        ArgVal =
          CastInst::createInferredCast(ArgVal, LLVMTy, NameStack.back(), CurBB);
      }
      assert(!LocStack.empty());
      Value *Loc = LocStack.back();
      if (cast<PointerType>(Loc->getType())->getElementType() != LLVMTy)
        // This cast only involves pointers, therefore BitCast
        Loc = CastInst::create(Instruction::BitCast, Loc,
                               PointerType::get(LLVMTy), "tmp", CurBB);

      new StoreInst(ArgVal, Loc, CurBB);
      AI->setName(NameStack.back());
      ++AI;
    }
------------------------------------------------

$:~/llvm/dst-directory/gcc$ svn info llvm-convert.cpp
Path: llvm-convert.cpp
Name: llvm-convert.cpp
URL: svn://anonsvn.opensource.apple.com/svn/llvm/trunk/gcc/llvm-convert.cpp
Repository Root: svn://anonsvn.opensource.apple.com/svn/llvm
Repository UUID: 51af6f4a-8115-0410-a7cd-c0d7a57f2c62
Revision: 224
Node Kind: file
Schedule: normal
Last Changed Author: jlaskey
Last Changed Rev: 219
Last Changed Date: 2006-12-01 01:54:57 -0800 (Fri, 01 Dec 2006)
Text Last Updated: 2006-12-09 13:16:41 -0800 (Sat, 09 Dec 2006)


          Domagoj
Comment 2 Anton Korobeynikov 2007-01-06 15:12:09 PST
Supplied source code includes some platform-dependent code (because it isn't
preprocessed).

However, it fails here too (on Linux/X86) but with another assertion:

cc1: /home/asl/proj/llvm/src/lib/VMCore/Instructions.cpp:1568: static
llvm::CastInst* llvm::CastInst::createIntegerCast(llvm::Value*, const
llvm::Type*, bool, const std::string&, llvm::BasicBlock*): Assertion
`C->getType()->isIntegral() && Ty->isIntegral() && "Invalid cast"' failed.


Will supply preprocessed & reduced source soon
Comment 3 Anton Korobeynikov 2007-01-06 15:20:33 PST
Created attachment 541 [details]
delta-reduced testcase

This file fails for me with TOT with assertion message printed before.
Comment 4 Domagoj 2007-01-06 15:28:54 PST
just to confirm that Anton's reduced testcase produces the same msg.

Domagoj
Comment 5 Chris Lattner 2007-01-06 17:16:18 PST
Verified, the reduced testcase crashes with TOT, investigating.
Comment 6 Chris Lattner 2007-01-06 17:25:06 PST
Further reduced testcase:

int svc_register (void (*dispatch) (int));

int svc_register (dispatch)
     void (*dispatch) ();
{}

Comment 7 Chris Lattner 2007-01-06 17:43:50 PST
Fixed.  Testcase here: test/Regression/CFrontend/2007-01-06-KNR-Proto.c

Patch sent to llvm-commits, but the mailing lists are apparently blocked, so no URL provided.

-Chris