This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Add support for STDC CX_LIMITED_RANGE pragma.
Needs ReviewPublic

Authored by jcranmer-intel on Feb 8 2022, 2:20 PM.

Details

Summary

This pragma is defined in the C specification. Notably, the C specification
makes the "DEFAULT" value identical to "OFF" for this pragma, unlike other
floating-point pragmas which are undefined behavior. This may be surprising to
some users.

This patch builds on, and requires, the complex intrinsics to make the pragmas
work properly.

Depends on D119290

Diff Detail

Event Timeline

jcranmer-intel created this revision.Feb 8 2022, 2:20 PM
jcranmer-intel requested review of this revision.Feb 8 2022, 2:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2022, 2:20 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added a subscriber: aaron.ballman.

Adding some more reviewers for visibility.

Please address the clang-format issues; also, this seems to be missing all of the test I would expect to see in Preprocessor or Parser for checking that the proper diagnostics are emitted or CodeGen tests for more complicated situations, like:

_Complex float range_scoped(_Complex float a, _Complex float b) {
// CHECK-COMMON: @range_scoped
// CHECK-COMMON: call{{.*}}complex.fmul{{.*}} #[[FULL]]
// CHECK-COMMON: call{{.*}}complex.fdiv{{.*}} #[[FULL]]
#pragma STDC CX_LIMITED_RANGE OFF
  _Complex float res = a * b;
  {
#pragma STDC CX_LIMITED_RANGE DEFAULT
    res += a / b;
#pragma STDC CX_LIMITED_RANGE OFF
    res += a / b;
  }
  return res;
}

What should the behavior be if this pragma is at file scope instead of block scope (should that be diagnosed)?

(Also, this functionality should get a release note and potentially some public documentation?)

clang/lib/Lex/Pragma.cpp
1028

Good catch, but do we have a test case for this change?

tahonermann resigned from this revision.Apr 14 2023, 1:41 PM

Resigning to remove this old review from my review queue.

Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 1:41 PM