llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

return value ignored

Open ahatanak opened this issue 15 years ago • 1 comments

Bugzilla Link 9557
Resolution INVALID
Resolved on Mar 25, 2011 18:17
Version trunk
OS Linux
CC @efriedma-quic

Extended Description

In the following example, main function in generated bit code does not return 0.

.c file

/* Verify whether math functions are simplified. */ double sin(double); double floor(double); float t(float a) { return sin(a); } float q(float a) { return floor(a); } double q1(float a) { return floor(a); } main() { #ifdef OPTIMIZE if (t(0)!=0) abort (); if (q(0)!=0) abort (); if (q1(0)!=0) abort (); #endif return 0; } attribute ((noinline)) double floor(double a) { abort (); } attribute ((noinline)) float floorf(float a) { return a; } attribute ((noinline)) double sin(double a) { abort (); } attribute ((noinline)) float sinf(float a) { return a; }

.ll file generated

clang tests-c/20030125-1.c -D OPTIMIZE=1 -emit-llvm -O1 -S -o -

; ModuleID = 'tests-c/20030125-1.c' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" target triple = "i386-pc-linux-gnu"

define float @​t(float %a) noreturn nounwind readnone { entry: unreachable }

define double @​sin(double %a) noreturn nounwind readnone noinline { entry: tail call void @​abort() noreturn nounwind unreachable }

define float @​q(float %a) noreturn nounwind { entry: %call = tail call double @​floor(double undef) unreachable }

define double @​floor(double %a) noreturn nounwind noinline { entry: tail call void @​abort() noreturn nounwind unreachable }

define double @​q1(float %a) noreturn nounwind { entry: %call = tail call double @​floor(double undef) unreachable }

define i32 @​main() nounwind { entry: unreachable }

declare void @​abort() noreturn

define float @​floorf(float %a) nounwind readnone noinline { entry: ret float %a }

define float @​sinf(float %a) nounwind readnone noinline { entry: ret float %a }

ahatanak avatar Mar 25 '11 23:03 ahatanak

Example has undefined behavior per the C standard. Note that clang does constant folding for math functions a bit differently from gcc.

efriedma-quic avatar Mar 26 '11 01:03 efriedma-quic