[PATCH] [openmp] Use correct argument separators in TSAN_OPTIONS

Tobias Ribizel via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 06:52:26 PDT 2020


Hi all,

I found a small bug/inconsistency between openmp and compiler-rt that 
causes a spurious warning to appear. A patch that fixes the issue is 
attached.

As this is my first contribution to LLVM, I am not familiar with the 
testing setup and was thus unable to quickly add a test for this bugfix. 
Maybe somebody with more experience can help out?

Best regards
Tobias Ribizel

--------------------
Currently, the parser used to tokenize the TSAN_OPTIONS in libomp uses
only spaces as separators, even though TSAN in compiler-rt supports
other separators like ':' or ','. This causes TSAN used with OpenMP to
spuriously display the following warning:

Warning: please export TSAN_OPTIONS='ignore_noninstrumented_modules=1'
to avoid false positive reports from the OpenMP runtime!

when TSAN_OPTIONS contains multiple arguments and
ignore_noninstrumented_modules follows a non-space separator.

CTest uses ':' to separate sanitizer options by default, which is
where I encountered this issue first in practice.

---
  openmp/tools/archer/ompt-tsan.cpp | 21 ++++++++++++++-------
  1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/openmp/tools/archer/ompt-tsan.cpp 
b/openmp/tools/archer/ompt-tsan.cpp
index d83cf04638d..3fe5a21c86a 100644
--- a/openmp/tools/archer/ompt-tsan.cpp
+++ b/openmp/tools/archer/ompt-tsan.cpp
@@ -15,6 +15,7 @@
  #define __STDC_FORMAT_MACROS
  #endif

+#include <algorithm>
  #include <atomic>
  #include <cassert>
  #include <cstdlib>
@@ -89,17 +90,23 @@ public:
    TsanFlags(const char *env) : ignore_noninstrumented_modules(0) {
      if (env) {
        std::vector<std::string> tokens;
-      std::string token;
        std::string str(env);
-      std::istringstream iss(str);
-      while (std::getline(iss, token, ' '))
-        tokens.push_back(token);
+      auto end = str.end();
+      auto it = str.begin();
+      auto is_sep = [](char c) {
+        return c == ' ' || c == ',' || c == ':' || c == '\n' || c == 
'\t' ||
+               c == '\r';
+      };
+      while (it != end) {
+        auto next_it = std::find_if(it, end, is_sep);
+        tokens.emplace_back(it, next_it);
+        it = next_it + 1;
+      }

-      for (std::vector<std::string>::iterator it = tokens.begin();
-           it != tokens.end(); ++it) {
+      for (const auto &token : tokens) {
          // we are interested in ignore_noninstrumented_modules to print a
          // warning
-        if (sscanf(it->c_str(), "ignore_noninstrumented_modules=%d",
+        if (sscanf(token.c_str(), "ignore_noninstrumented_modules=%d",
                     &ignore_noninstrumented_modules))
            continue;
        }
-- 
2.26.2


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5262 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200703/6ad5bb0c/attachment.bin>


More information about the llvm-commits mailing list