[Openmp-commits] [openmp] r319811 - Fix alignment in teams-reduction.c test

Jonas Hahnfeld via Openmp-commits openmp-commits at lists.llvm.org
Tue Dec 5 10:45:21 PST 2017


Author: hahnfeld
Date: Tue Dec  5 10:45:21 2017
New Revision: 319811

URL: http://llvm.org/viewvc/llvm-project?rev=319811&view=rev
Log:
Fix alignment in teams-reduction.c test

The runtime will use the global kmp_critical_name as a lock and
tries to atomically store a pointer in there. This will fail
if the global is only aligned by 4 bytes, the size of one int32_t
element. Use a union to ensure the global is aligned to the size
of a pointer on the current platform.

Modified:
    openmp/trunk/runtime/test/misc_bugs/teams-reduction.c

Modified: openmp/trunk/runtime/test/misc_bugs/teams-reduction.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/misc_bugs/teams-reduction.c?rev=319811&r1=319810&r2=319811&view=diff
==============================================================================
--- openmp/trunk/runtime/test/misc_bugs/teams-reduction.c (original)
+++ openmp/trunk/runtime/test/misc_bugs/teams-reduction.c Tue Dec  5 10:45:21 2017
@@ -30,7 +30,12 @@ typedef struct {
 
 static ident_t dummy_loc = {0, 2, 0, 0, ";dummyFile;dummyFunc;0;0;;"};
 
-typedef int32_t kmp_critical_name[8];
+typedef union {
+  // The global will be used as pointer, so we need to make sure that the
+  // compiler correctly aligns the global...
+  void *ptr;
+  int32_t data[8];
+} kmp_critical_name;
 kmp_critical_name crit;
 
 int32_t __kmpc_global_thread_num(ident_t *);




More information about the Openmp-commits mailing list