Skip to content

floating point exceptions flags are ignored in constant folding #4302

@llvmbot

Description

@llvmbot
Bugzilla Link 3930
Resolution INVALID
Resolved on Apr 02, 2009 22:42
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor

Extended Description

I toyed around with http://llvm.org/demo/index.cgi

and found that this code :
#include <stdio.h>
#include <fenv.h>

int main(int argc, char **argv) {
#pragma STDC FENV_ACCESS ON
feclearexcept(FE_DIVBYZERO);
double d = 1.0/0.0;
if (fetestexcept(FE_DIVBYZERO))
printf("error\n");
else
printf("%e\n", d);
return 0;
}

is compiled this way :

define i32 @​main(i32 %argc, i8** nocapture %argv) nounwind {
entry:
%0 = tail call i32 @​feclearexcept(i32 4) nounwind ; [#uses=0]
%1 = tail call i32 @​fetestexcept(i32 4) nounwind ; [#uses=1]
%2 = icmp eq i32 %1, 0 ; [#uses=1]
br i1 %2, label %bb1, label %bb

bb: ; preds = %entry
%3 = tail call i32 @​puts(i8* getelementptr ([6 x i8]* @.str, i32 0, i32 0)) nounwind ; [#uses=0]
ret i32 0

bb1: ; preds = %entry
%4 = tail call i32 (i8*, ...)* @​printf(i8* noalias getelementptr ([4 x i8]* @.str1, i32 0, i32 0), double 0x7FF0000000000000) nounwind ; [#uses=0]
ret i32 0
}

it as basically no chance to print "error" like it does under a normal C compiler (tested on normal gcc x86_32).

the pragma is here to tell the compiler maker to be careful in floating point handling because there will be some tampering with the FP subsystem.

exactly the same kind of bug as Bug 3929

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillainvalidResolved as invalid, i.e. not a bugmiscompilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions