[commit: hsc2hs] master: Make hsc_alignment work in clang (d7e49a6)

git at git.haskell.org git at git.haskell.org
Wed Mar 15 22:32:09 UTC 2017


Repository : ssh://git@git.haskell.org/hsc2hs

On branch  : master
Link       : http://git.haskell.org/hsc2hs.git/commitdiff/d7e49a6d90dbd3d8d0bbace9410fe8411a1c77bb

>---------------------------------------------------------------

commit d7e49a6d90dbd3d8d0bbace9410fe8411a1c77bb
Author: Bartosz Nitka <bnitka at fb.com>
Date:   Wed Mar 15 17:52:36 2017 -0400

    Make hsc_alignment work in clang
    
    Summary:
    With the old definition clang gives this error:
    ```
    error: '(anonymous struct at example.cpp:15:3)'
      cannot be defined in a type specifier
    ```
    This makes it work under clang.
    
    Test Plan:
    Test with https://godbolt.org/g/kIBwyP and look at the
    assembly.
    
    Reviewers: O25 HSC2HS, hvr, austin, bgamari, mpickering
    
    Reviewed By: bgamari
    
    Subscribers: simonmar
    
    Differential Revision: https://phabricator.haskell.org/D3346


>---------------------------------------------------------------

d7e49a6d90dbd3d8d0bbace9410fe8411a1c77bb
 template-hsc.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/template-hsc.h b/template-hsc.h
index 71832f5..dec0e43 100644
--- a/template-hsc.h
+++ b/template-hsc.h
@@ -88,8 +88,14 @@ void *hsc_stdout(void);
 #define hsc_size(t...) \
     hsc_printf("(%ld)", (long) sizeof(t));
 
-#define hsc_alignment(t...) \
-    hsc_printf("(%ld)", (long) offsetof(struct {char x__; t (y__); }, y__));
+#define hsc_alignment(x...)                                           \
+  do {                                                                \
+    struct __anon_x__ {                                               \
+      char a;                                                         \
+      x b;                                                            \
+    };                                                                \
+    hsc_printf("%lu", (unsigned long)offsetof(struct __anon_x__, b)); \
+  } while (0)
 
 #define hsc_enum(t, f, print_name, x)                   \
     print_name;                                         \



More information about the ghc-commits mailing list