Skip to content

New IRgen of 'if' with constants is broken. #3432

@llvmbot

Description

@llvmbot
Bugzilla Link 3060
Resolution FIXED
Resolved on Mar 06, 2010 13:59
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @lattner,@efriedma-quic,@nunoplopes,@regehr

Extended Description

The new constant IRgen is too aggressive because it is possible to evaluate expressions with side effects to constants.

ddunbar@lordcrumb:CodeGen$ cat if.c
int g0(void);

int f0(void) {
if (g0() && 0)
return 0;
return 1;
}
ddunbar@lordcrumb:CodeGen$ clang -emit-llvm -o - -O3 if.c
; ModuleID = 'if.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:128:128"
target triple = "i686-apple-darwin10.0.0d3"

define i32 @​f0() nounwind readnone {
entry:
ret i32 1
}

The same issue occurs in other places, for example with the comma operator.

Chris and I discussed and came up with a plan to have tryEvaluate return more information about the folded constant. The idea would be to have the result be one of
(1) not evaluatable
(2) C99 ICE, which should never have side effects or labels
(3) constant value bla, with optional bits indicating if the expression has side effects and if the expression has labels (useful for consumers in different contexts). One can imagine other bits like imprecise-floating-point result being useful in time.

This bug is a placeholder for this work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:codegenIR generation bugs: mangling, exceptions, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions