[LLVMbugs] [Bug 12384] New: Clang miscompiles trivial init-family methods if the return type is unexpected
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Mar 28 04:47:29 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=12384
Bug #: 12384
Summary: Clang miscompiles trivial init-family methods if the
return type is unexpected
Product: clang
Version: unspecified
Platform: PC
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: csdavec at swan.ac.uk
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
This simple method:
@interface Fail @end
@protocol X @end
@implementation Fail
- (id<X>) initWithX
{
return (id)self;
}
@end
When compiled with clang, the first thing you'll spot is a very strange error:
banlu.m:8:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
Control obviously doesn't reach the end of the function - the line before this
is a return statement!
However, checking the generated IR, it appears that it does:
define internal i8* @"\01-[Fail initWithX]"(%0* %self, i8* %_cmd) nounwind
uwtable {
entry:
%retval = alloca i8*, align 8
%self.addr = alloca %0*, align 8
%_cmd.addr = alloca i8*, align 8
store %0* %self, %0** %self.addr, align 8
store i8* %_cmd, i8** %_cmd.addr, align 8
%0 = load i8** %retval
ret i8* %0
}
Note that retval is never written to. This becomes clearer with optimisation
enabled:
define internal noalias i8* @"\01-[Fail initWithX]"(%0* nocapture %self, i8*
nocapture %_cmd) nounwind uwtable readnone {
entry:
ret i8* undef
}
This is obviously wrong.
This is independent of the Objective-C runtime being targeted - it appears that
the return statement never makes it into the AST at all...
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list