[PATCH] D98895: [X86][Draft] Disable long double type for -mno-x87 option

Andrew Savonichev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 19 08:30:02 PDT 2021


asavonic added inline comments.


================
Comment at: clang/test/Sema/x86-no-x87.c:48-61
+void assign2() {
+  struct st_long_double st;
+#ifndef NOERROR
+  // expected-error at +2{{long double is not supported on this target}}
+#endif
+  st.ld = 0.42;
+}
----------------
pengfei wrote:
> These seems pass with GCC. https://godbolt.org/z/qM4nWhThx
Right. Assignment of a literal is compiled to just `mov` without any x87 instructions, so it is not diagnosed by GCC. On the other hand, assignment of a variable does trigger the error:

    void assign4(double d) {
      struct st_long_double st;
      st.ld = d; // error: long double is not supported on this target
    }

We can update the patch to do the same for some cases, but it does not look very consistent, and makes assumptions on how the code is optimized and compiled.

GCC has an advantage here, because it emits the diagnostic at a lower level after at lease some optimizations are done. For example, the following code does not trigger an error for GCC because of inlining:

    double get_const() {
      return 0.42;
    }
    void assign5(struct st_long_double *st) {
      st->ld = get_const();
    }



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98895/new/

https://reviews.llvm.org/D98895



More information about the cfe-commits mailing list