[Openmp-commits] [PATCH] D53442: Initialize variables before assignment in asm

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Oct 19 10:11:15 PDT 2018


protze.joachim created this revision.
protze.joachim added a reviewer: jlpeyton.
Herald added subscribers: kristof.beyls, javed.absar.

When applying MemorySanitizer to an OpenMP application, msan complains about uninitialized access for these variables, which are assigned in assembler code. With these changes, I could successfully apply MemorySanitizer to an OpenMP application.

If the initialization is considered harmful, an alternative would be to wrap the initialization in

  #if defined(__has_feature)
  #  if __has_feature(memory_sanitizer)
  // code that builds only under MemorySanitizer
  #  endif
  #endif


Repository:
  rOMP OpenMP

https://reviews.llvm.org/D53442

Files:
  runtime/src/kmp_affinity.cpp
  runtime/src/kmp_runtime.cpp
  runtime/src/kmp_utility.cpp


Index: runtime/src/kmp_utility.cpp
===================================================================
--- runtime/src/kmp_utility.cpp
+++ runtime/src/kmp_utility.cpp
@@ -121,7 +121,7 @@
 } // func __kmp_parse_cpu_frequency
 
 void __kmp_query_cpuid(kmp_cpuinfo_t *p) {
-  struct kmp_cpuid buf;
+  struct kmp_cpuid buf = {0, 0, 0, 0};
   int max_arg;
   int log_per_phy;
 #ifdef KMP_DEBUG
Index: runtime/src/kmp_runtime.cpp
===================================================================
--- runtime/src/kmp_runtime.cpp
+++ runtime/src/kmp_runtime.cpp
@@ -1101,8 +1101,8 @@
 // structure, so we don't make changes unless they are needed.
 inline static void propagateFPControl(kmp_team_t *team) {
   if (__kmp_inherit_fp_control) {
-    kmp_int16 x87_fpu_control_word;
-    kmp_uint32 mxcsr;
+    kmp_int16 x87_fpu_control_word = 0;
+    kmp_uint32 mxcsr = 0;
 
     // Get master values of FPU control flags (both X87 and vector)
     __kmp_store_x87_fpu_control_word(&x87_fpu_control_word);
@@ -1136,8 +1136,8 @@
   if (__kmp_inherit_fp_control && team->t.t_fp_control_saved) {
     // Only reset the fp control regs if they have been changed in the team.
     // the parallel region that we are exiting.
-    kmp_int16 x87_fpu_control_word;
-    kmp_uint32 mxcsr;
+    kmp_int16 x87_fpu_control_word = 0;
+    kmp_uint32 mxcsr = 0;
     __kmp_store_x87_fpu_control_word(&x87_fpu_control_word);
     __kmp_store_mxcsr(&mxcsr);
     mxcsr &= KMP_X86_MXCSR_MASK;
Index: runtime/src/kmp_affinity.cpp
===================================================================
--- runtime/src/kmp_affinity.cpp
+++ runtime/src/kmp_affinity.cpp
@@ -1405,7 +1405,7 @@
 // based on cpuid leaf 11.
 static int __kmp_affinity_create_x2apicid_map(AddrUnsPair **address2os,
                                               kmp_i18n_id_t *const msg_id) {
-  kmp_cpuid buf;
+  kmp_cpuid buf = {0, 0, 0, 0};
   *address2os = NULL;
   *msg_id = kmp_i18n_null;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53442.170213.patch
Type: text/x-patch
Size: 1942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20181019/fbf2a605/attachment.bin>


More information about the Openmp-commits mailing list