From 8707744ae5f778c005d6c29342fe01cb654527af Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 18 Dec 2019 09:51:22 -0500 Subject: [PATCH] [GCChecker] fixes for running C++ analysis on macOS (#34095) --- src/Makefile | 6 ++++-- src/clangsa/GCChecker.cpp | 9 ++++++++- src/debuginfo.cpp | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index 72f89dc71f041..2ec26db982088 100644 --- a/src/Makefile +++ b/src/Makefile @@ -378,19 +378,21 @@ endif # make CC=~+/../usr/tools/clang CXX=~+/../usr/tools/clang USECLANG=1 analyzegc # make USECLANG=1 clang-sa-* CLANGSA_FLAGS := +CLANGSA_CXXFLAGS := ifeq ($(OS), Darwin) # on new XCode, the files are hidden CLANGSA_FLAGS += -isysroot $(shell xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk +CLANGSA_CXXFLAGS += -isystem $(shell xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 endif ifeq ($(USEGCC),1) # try to help clang find the c++ files for CC by guessing the value for --prefix # by dropping lib/gcc// from the install directory it reports -CLANGSA_FLAGS += --gcc-toolchain="$(abspath $(shell LANG=C $(CC) -print-search-dirs | grep '^install: ' | sed -e "s/^install: //")/../../../..)" +CLANGSA_CXXFLAGS += --gcc-toolchain="$(abspath $(shell LANG=C $(CC) -print-search-dirs | grep '^install: ' | sed -e "s/^install: //")/../../../..)" endif clang-sa-%: $(SRCDIR)/%.c $(build_shlibdir)/libGCCheckerPlugin.$(SHLIB_EXT) | analyzegc-deps-check @$(call PRINT_ANALYZE, $(build_depsbindir)/clang --analyze -Xanalyzer -analyzer-werror -Xanalyzer -analyzer-output=text -Xclang -load -Xclang $(build_shlibdir)/libGCCheckerPlugin.$(SHLIB_EXT) $(CLANGSA_FLAGS) $(JCPPFLAGS) $(JCFLAGS) $(DEBUGFLAGS) -Xclang -analyzer-checker=core$(COMMA)julia.GCChecker --analyzer-no-default-checks -fcolor-diagnostics -Werror -x c $<) clang-sa-%: $(SRCDIR)/%.cpp $(build_shlibdir)/libGCCheckerPlugin.$(SHLIB_EXT) | analyzegc-deps-check - @$(call PRINT_ANALYZE, $(build_depsbindir)/clang --analyze -Xanalyzer -analyzer-werror -Xanalyzer -analyzer-output=text -Xclang -load -Xclang $(build_shlibdir)/libGCCheckerPlugin.$(SHLIB_EXT) $(CLANGSA_FLAGS) $(LLVM_CXXFLAGS) $(JCPPFLAGS) $(JCXXFLAGS) $(DEBUGFLAGS) -Xclang -analyzer-checker=core$(COMMA)julia.GCChecker --analyzer-no-default-checks -fcolor-diagnostics -Werror -x c++ $<) + @$(call PRINT_ANALYZE, $(build_depsbindir)/clang --analyze -Xanalyzer -analyzer-werror -Xanalyzer -analyzer-output=text -Xclang -load -Xclang $(build_shlibdir)/libGCCheckerPlugin.$(SHLIB_EXT) $(CLANGSA_FLAGS) $(CLANGSA_CXXFLAGS) $(LLVM_CXXFLAGS) $(JCPPFLAGS) $(JCXXFLAGS) $(DEBUGFLAGS) -Xclang -analyzer-checker=core$(COMMA)julia.GCChecker --analyzer-no-default-checks -fcolor-diagnostics -Werror -x c++ $<) # Add C files as a target of `analyzegc` analyzegc: $(addprefix clang-sa-,$(RUNTIME_SRCS)) diff --git a/src/clangsa/GCChecker.cpp b/src/clangsa/GCChecker.cpp index 7458a1e994f8c..787197baa85ba 100644 --- a/src/clangsa/GCChecker.cpp +++ b/src/clangsa/GCChecker.cpp @@ -770,6 +770,13 @@ bool GCChecker::isSafepoint(const CallEvent &Call) const if (const TypedefType *TDT = dyn_cast(Callee->getType())) { isCalleeSafepoint = !declHasAnnotation(TDT->getDecl(), "julia_not_safepoint"); } + else if (const CXXPseudoDestructorExpr *PDE = dyn_cast(Callee)) { + // A pseudo-destructor is an expression that looks like a member + // access to a destructor of a scalar type. A pseudo-destructor + // expression has no run-time semantics beyond evaluating the base + // expression (which would have it's own CallEvent, if applicable). + isCalleeSafepoint = false; + } } else if (FD) { if (FD->getBuiltinID() != 0 || FD->isTrivial()) isCalleeSafepoint = false; @@ -778,7 +785,7 @@ bool GCChecker::isSafepoint(const CallEvent &Call) const FD->getName().startswith_lower("unw_") || FD->getName().startswith("_U")) && FD->getName() != "uv_run") - isCalleeSafepoint = false; + isCalleeSafepoint = false; else isCalleeSafepoint = !isFDAnnotatedNotSafepoint(FD); } diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index 01ae6120f2923..329474db298a6 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -588,7 +588,7 @@ typedef struct { typedef std::map obfiletype; static obfiletype objfilemap; -static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) +static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) JL_NOTSAFEPOINT { for (auto Load : obj->load_commands()) { @@ -885,7 +885,7 @@ static objfileentry_t &find_object_file(uint64_t fbase, StringRef fname) JL_NOTS // the DebugSymbols framework is moved or removed, an alternative would // be to directly query Spotlight for the dSYM bundle. - typedef CFURLRef (*DBGCopyFullDSYMURLForUUIDfn)(CFUUIDRef, CFURLRef); + typedef CFURLRef (*DBGCopyFullDSYMURLForUUIDfn)(CFUUIDRef, CFURLRef) JL_NOTSAFEPOINT; DBGCopyFullDSYMURLForUUIDfn DBGCopyFullDSYMURLForUUID = NULL; // First, try to load the private DebugSymbols framework.