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 10409 - Clang does not support the FENV_ACCESS pragma
Summary: Clang does not support the FENV_ACCESS pragma
Status: RESOLVED DUPLICATE of bug 8100
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
: 10408 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-07-19 11:49 PDT by Fred J. Tydeman
Modified: 2012-05-26 11:36 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fred J. Tydeman 2011-07-19 11:49:13 PDT
It appears, that even with -O0, some "optimizations" are being done. 
These optimizations change the semantics (meaning) of the code and
do the wrong thing.  One such item is constant folding.

#include <fenv.h>
#include <stdio.h>
#pragma STDC FENV_ACCESS ON

int main(void){
  double x;
  int i;

  feclearexcept(FE_ALL_EXCEPT);

  x = 1.0;
  x /= 3.0;  /* should raise inexact; 
                value computed depends upon rounding direction */

  i = fetestexcept(FE_ALL_EXCEPT);
  if( FE_INEXACT != i ){
    printf("missing inexact (got %i), x=%g\n", i, x);
  }
  return 0;
]

If I add 'volatile' to the declaration of x, then the code works.
The same kind of problem happens for:
  x=1.0; x /= 0.0;  /* divide by zero */
  x=0.0; x /= 0.0;  /* invalid */
  x=DBL_MAX; x *= DBL_MAX;  /* overflow */
  x=DBL_MIN; x *= DBL_MIN;  /* underflow */
Comment 1 Chris Lattner 2011-07-19 11:55:03 PDT
C requires constant folding in various places, and "not doing optimization" is not a bug.

The problem is that clang doesn't support the FENV_ACCESS pragma, and LLVM IR doesn't support a way to express it.

-Chris
Comment 2 Chris Lattner 2011-07-19 11:56:16 PDT
*** Bug 10408 has been marked as a duplicate of this bug. ***
Comment 3 Chris Lattner 2012-05-26 11:36:19 PDT

*** This bug has been marked as a duplicate of bug 8100 ***