]> granicus.if.org Git - clang/commitdiff
Add VFS support for sanitizers' blacklist
authorJan Korous <jkorous@apple.com>
Mon, 7 Oct 2019 22:36:19 +0000 (22:36 +0000)
committerJan Korous <jkorous@apple.com>
Mon, 7 Oct 2019 22:36:19 +0000 (22:36 +0000)
Differential Revision: https://reviews.llvm.org/D67742

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373977 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml [new file with mode: 0644]
test/CodeGen/ubsan-blacklist.c

index a41b64ffcc81fd1c17c1f945d3626f407218c359..906c54194d942db2cb412a9c4accbd3c1e0bfa33 100644 (file)
@@ -72,6 +72,7 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -81,6 +82,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cassert>
@@ -826,6 +828,18 @@ static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI,
   llvm_unreachable("getAddressSpaceMapMangling() doesn't cover anything.");
 }
 
+static std::vector<std::string>
+getRealPaths(llvm::vfs::FileSystem &VFS, llvm::ArrayRef<std::string> Paths) {
+  std::vector<std::string> Result;
+  llvm::SmallString<128> Buffer;
+  for (const auto &File : Paths) {
+    if (std::error_code EC = VFS.getRealPath(File, Buffer))
+      llvm::report_fatal_error("can't open file '" + File + "': " + EC.message());
+    Result.push_back(Buffer.str());
+  }
+  return Result;
+}
+
 ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM,
                        IdentifierTable &idents, SelectorTable &sels,
                        Builtin::Context &builtins)
@@ -833,7 +847,10 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM,
       TemplateSpecializationTypes(this_()),
       DependentTemplateSpecializationTypes(this_()),
       SubstTemplateTemplateParmPacks(this_()), SourceMgr(SM), LangOpts(LOpts),
-      SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, SM)),
+      SanitizerBL(new SanitizerBlacklist(
+          getRealPaths(SM.getFileManager().getVirtualFileSystem(),
+                       LangOpts.SanitizerBlacklistFiles),
+          SM)),
       XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles,
                                         LangOpts.XRayNeverInstrumentFiles,
                                         LangOpts.XRayAttrListFiles, SM)),
diff --git a/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml b/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml
new file mode 100644 (file)
index 0000000..df2b221
--- /dev/null
@@ -0,0 +1,15 @@
+{
+  'version': 0,
+  'roots': [
+    { 'name': '@DIR@', 'type': 'directory',
+      'contents': [
+        { 'name': 'only-virtual-file.blacklist', 'type': 'file',
+          'external-contents': '@REAL_FILE@'
+        },
+        { 'name': 'invalid-virtual-file.blacklist', 'type': 'file',
+          'external-contents': '@NONEXISTENT_FILE@'
+        }
+      ]
+    }
+  ]
+}
index 666003bd9233c1c47e2cec749022a97bc287ce62..d6b4b714314809ada08db0533828abae9755ede0 100644 (file)
@@ -5,6 +5,17 @@
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -fsanitize-blacklist=%t-func.blacklist -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -fsanitize-blacklist=%t-file.blacklist -emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
 
+// RUN: rm -f %t-vfsoverlay.yaml
+// RUN: rm -f %t-nonexistent.blacklist
+// RUN: sed -e "s|@DIR@|%T|g" %S/Inputs/sanitizer-blacklist-vfsoverlay.yaml | sed -e "s|@REAL_FILE@|%t-func.blacklist|g" | sed -e "s|@NONEXISTENT_FILE@|%t-nonexistent.blacklist|g" > %t-vfsoverlay.yaml
+// RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay %t-vfsoverlay.yaml -fsanitize-blacklist=%T/only-virtual-file.blacklist -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+
+// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay %t-vfsoverlay.yaml -fsanitize-blacklist=%T/invalid-virtual-file.blacklist -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID-MAPPED-FILE
+// INVALID-MAPPED-FILE: invalid-virtual-file.blacklist': No such file or directory
+
+// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay %t-vfsoverlay.yaml -fsanitize-blacklist=%t-nonexistent.blacklist -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID
+// INVALID: nonexistent.blacklist': No such file or directory
+
 unsigned i;
 
 // DEFAULT: @hash