On Fri, Jan 14, 2022 at 03:17:21PM +0100, Tobias Heider wrote:
> Hi,
> 
> clang ships with a pretty useful static analyzer to find all kinds of bugs
> in C and C++ code:
> 
> https://clang-analyzer.llvm.org/
> 
> I use it regularly to check my own diffs and found plenty of bugs I could
> have missed otherwise.  While we have the code in base we don't actually
> build it into our libclang currently, so the only ways to use it are
> manually modifying the Makefiles or installing llvm from ports.
> 
> I was wondering if anyone else uses this and if there was any interest to
> have this in our base clang?
> 
> diff --git gnu/usr.bin/clang/Makefile gnu/usr.bin/clang/Makefile
> index 6cf71d36cf8..b47abc02474 100644
> --- gnu/usr.bin/clang/Makefile
> +++ gnu/usr.bin/clang/Makefile
> @@ -39,6 +39,11 @@ SUBDIR+=libclangSerialization
>  SUBDIR+=libclangFrontend
>  SUBDIR+=libclangRewriteFrontend
>  SUBDIR+=libclangFrontendTool
> +SUBDIR+=libclangASTMatchers
> +SUBDIR+=libclangCrossTU
> +SUBDIR+=libclangStaticAnalyzer
> +SUBDIR+=libclangIndex
> +SUBDIR+=libclangTooling
>  
>  SUBDIR+=clang
>  
> diff --git gnu/usr.bin/clang/clang/Makefile gnu/usr.bin/clang/clang/Makefile
> index 76535ee8842..7d3847f883d 100644
> --- gnu/usr.bin/clang/clang/Makefile
> +++ gnu/usr.bin/clang/clang/Makefile
> @@ -43,6 +43,11 @@ LLVM_LIBDEPS=      LLVM \
>               clangEdit \
>               clangAST \
>               clangLex \
> -             clangBasic
> +             clangBasic \
> +             clangStaticAnalyzer \
> +             clangCrossTU \
> +             clangASTMatchers \
> +             clangIndex \
> +             clangTooling \
>  
>  .include <bsd.prog.mk>
> diff --git gnu/usr.bin/clang/include/clang/Config/config.h 
> gnu/usr.bin/clang/include/clang/Config/config.h
> index 02a049bf2be..93494d6a0b1 100644
> --- gnu/usr.bin/clang/include/clang/Config/config.h
> +++ gnu/usr.bin/clang/include/clang/Config/config.h
> @@ -78,7 +78,7 @@
>  /* Enable each functionality of modules */
>  #define CLANG_ENABLE_ARCMT 0
>  #define CLANG_ENABLE_OBJC_REWRITER 0
> -#define CLANG_ENABLE_STATIC_ANALYZER 0
> +#define CLANG_ENABLE_STATIC_ANALYZER 1
>  
>  /* Spawn a new process clang.exe for the CC1 tool invocation, when necessary 
> */
>  #define CLANG_SPAWN_CC1 0
> diff --git gnu/usr.bin/clang/libclangASTMatchers/Makefile 
> gnu/usr.bin/clang/libclangASTMatchers/Makefile
> new file mode 100644
> index 00000000000..76c79c738cb
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangASTMatchers/Makefile
> @@ -0,0 +1,25 @@
> +LIB= clangASTMatchers
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=    ${CLANG_INCLUDES}
> +
> +.include <bsd.own.mk>
> +
> +# Core
> +SRCS+=       ASTMatchFinder.cpp \
> +     ASTMatchersInternal.cpp \
> +     GtestMatchers.cpp \
> +     Diagnostics.cpp \
> +     Marshallers.cpp \
> +     Parser.cpp \
> +     Registry.cpp \
> +     VariantValue.cpp \
> +
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/ASTMatchers
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/ASTMatchers/Dynamic
> +
> +install:
> +     @# Nothing here so far ...
> +
> +.include <bsd.lib.mk>
> diff --git gnu/usr.bin/clang/libclangAnalysis/Makefile 
> gnu/usr.bin/clang/libclangAnalysis/Makefile
> index 25669a34cc0..7be18f24685 100644
> --- gnu/usr.bin/clang/libclangAnalysis/Makefile
> +++ gnu/usr.bin/clang/libclangAnalysis/Makefile
> @@ -23,6 +23,7 @@ SRCS=       AnalysisDeclContext.cpp \
>       ExprMutationAnalyzer.cpp \
>       IssueHash.cpp \
>       LiveVariables.cpp \
> +     MacroExpansionContext.cpp \
>       ObjCNoReturn.cpp \
>       PathDiagnostic.cpp \
>       PostOrderCFGView.cpp \
> diff --git gnu/usr.bin/clang/libclangCrossTU/Makefile 
> gnu/usr.bin/clang/libclangCrossTU/Makefile
> new file mode 100644
> index 00000000000..59541bce012
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangCrossTU/Makefile
> @@ -0,0 +1,17 @@
> +LIB= clangCrossTU
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=   -I ${.CURDIR}/../../../llvm/clang/lib/CrossTU
> +CPPFLAGS+=    ${CLANG_INCLUDES}
> +
> +.include <bsd.own.mk>
> +
> +SRCS+=       CrossTranslationUnit.cpp \
> +
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/CrossTU/
> +
> +install:
> +     @# Nothing here so far ...
> +
> +.include <bsd.lib.mk>
> diff --git gnu/usr.bin/clang/libclangIndex/Makefile 
> gnu/usr.bin/clang/libclangIndex/Makefile
> new file mode 100644
> index 00000000000..b31d906a5ee
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangIndex/Makefile
> @@ -0,0 +1,18 @@
> +LIB= clangIndex
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=   -I ${.CURDIR}/../../../llvm/clang/lib/Index
> +CPPFLAGS+=    ${CLANG_INCLUDES}
> +
> +.include <bsd.own.mk>
> +
> +SRCS+=       CommentToXML.cpp \
> +     USRGeneration.cpp \
> +
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/Index/
> +
> +install:
> +     @# Nothing here so far ...
> +
> +.include <bsd.lib.mk>
> diff --git gnu/usr.bin/clang/libclangStaticAnalyzer/Makefile 
> gnu/usr.bin/clang/libclangStaticAnalyzer/Makefile
> new file mode 100644
> index 00000000000..6d152afe283
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangStaticAnalyzer/Makefile
> @@ -0,0 +1,206 @@
> +LIB= clangStaticAnalyzer
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=   -I ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Checkers
> +CPPFLAGS+=    ${CLANG_INCLUDES}
> +
> +.include <bsd.own.mk>
> +
> +# Core
> +SRCS+=       APSIntType.cpp \
> +     AnalysisManager.cpp \
> +     AnalyzerOptions.cpp \
> +     BasicValueFactory.cpp \
> +     BlockCounter.cpp \
> +     BugReporter.cpp \
> +     BugReporterVisitors.cpp \
> +     CallEvent.cpp \
> +     Checker.cpp \
> +     CheckerContext.cpp \
> +     CheckerHelpers.cpp \
> +     CheckerManager.cpp \
> +     CheckerRegistryData.cpp \
> +     CommonBugCategories.cpp \
> +     ConstraintManager.cpp \
> +     CoreEngine.cpp \
> +     DynamicExtent.cpp \
> +     DynamicType.cpp \
> +     Environment.cpp \
> +     ExplodedGraph.cpp \
> +     ExprEngine.cpp \
> +     ExprEngineC.cpp \
> +     ExprEngineCXX.cpp \
> +     ExprEngineCallAndReturn.cpp \
> +     ExprEngineObjC.cpp \
> +     FunctionSummary.cpp \
> +     HTMLDiagnostics.cpp \
> +     LoopUnrolling.cpp \
> +     LoopWidening.cpp \
> +     MemRegion.cpp \
> +     PlistDiagnostics.cpp \
> +     ProgramState.cpp \
> +     RangeConstraintManager.cpp \
> +     RangedConstraintManager.cpp \
> +     RegionStore.cpp \
> +     SMTConstraintManager.cpp \
> +     SValBuilder.cpp \
> +     SVals.cpp \
> +     SarifDiagnostics.cpp \
> +     SimpleConstraintManager.cpp \
> +     SimpleSValBuilder.cpp \
> +     Store.cpp \
> +     SymbolManager.cpp \
> +     TextDiagnostics.cpp \
> +     WorkList.cpp \
> +
> +# Frontend
> +SRCS+=       AnalysisConsumer.cpp \
> +     AnalyzerHelpFlags.cpp \
> +     CheckerRegistry.cpp \
> +     CreateCheckerManager.cpp \
> +     FrontendActions.cpp \
> +     ModelConsumer.cpp \
> +     ModelInjector.cpp \
> +
> +# Checkers
> +SRCS+=       AnalysisOrderChecker.cpp \
> +     AnalyzerStatsChecker.cpp \
> +     ArrayBoundChecker.cpp \
> +     ArrayBoundCheckerV2.cpp \
> +     BlockInCriticalSectionChecker.cpp \
> +     BoolAssignmentChecker.cpp \
> +     BuiltinFunctionChecker.cpp \
> +     CStringChecker.cpp \
> +     CStringSyntaxChecker.cpp \
> +     CallAndMessageChecker.cpp \
> +     CastSizeChecker.cpp \
> +     CastToStructChecker.cpp \
> +     CastValueChecker.cpp \
> +     CheckSecuritySyntaxOnly.cpp \
> +     CheckSizeofPointer.cpp \
> +     CheckerDocumentation.cpp \
> +     ChrootChecker.cpp \
> +     CloneChecker.cpp \
> +     ConversionChecker.cpp \
> +     DeadStoresChecker.cpp \
> +     DebugCheckers.cpp \
> +     DereferenceChecker.cpp \
> +     DivZeroChecker.cpp \
> +     ExprInspectionChecker.cpp \
> +     FixedAddressChecker.cpp \
> +     GenericTaintChecker.cpp \
> +     IdenticalExprChecker.cpp \
> +     InnerPointerChecker.cpp \
> +     InvalidatedIteratorChecker.cpp \
> +     IvarInvalidationChecker.cpp \
> +     LocalizationChecker.cpp \
> +     MallocChecker.cpp \
> +     MallocOverflowSecurityChecker.cpp \
> +     MallocSizeofChecker.cpp \
> +     MismatchedIteratorChecker.cpp \
> +     MmapWriteExecChecker.cpp \
> +     NSAutoreleasePoolChecker.cpp \
> +     NSErrorChecker.cpp \
> +     NoReturnFunctionChecker.cpp \
> +     NonNullParamChecker.cpp \
> +     NonnullGlobalConstantsChecker.cpp \
> +     NullabilityChecker.cpp \
> +     NumberObjectConversionChecker.cpp \
> +     PaddingChecker.cpp \
> +     PointerArithChecker.cpp \
> +     PointerIterationChecker.cpp \
> +     PointerSortingChecker.cpp \
> +     PointerSubChecker.cpp \
> +     PthreadLockChecker.cpp \
> +     ReturnPointerRangeChecker.cpp \
> +     ReturnUndefChecker.cpp \
> +     ReturnValueChecker.cpp \
> +     RunLoopAutoreleaseLeakChecker.cpp \
> +     SimpleStreamChecker.cpp \
> +     StackAddrEscapeChecker.cpp \
> +     StdLibraryFunctionsChecker.cpp \
> +     StreamChecker.cpp \
> +     Taint.cpp \
> +     TaintTesterChecker.cpp \
> +     TestAfterDivZeroChecker.cpp \
> +     TraversalChecker.cpp \
> +     TrustNonnullChecker.cpp \
> +     UndefBranchChecker.cpp \
> +     UndefCapturedBlockVarChecker.cpp \
> +     UndefResultChecker.cpp \
> +     UndefinedArraySubscriptChecker.cpp \
> +     UndefinedAssignmentChecker.cpp \
> +     UnixAPIChecker.cpp \
> +     UnreachableCodeChecker.cpp \
> +     VLASizeChecker.cpp \
> +     ValistChecker.cpp \
> +     VforkChecker.cpp \
> +     VirtualCallChecker.cpp \
> +     BasicObjCFoundationChecks.cpp \
> +     CheckObjCDealloc.cpp \
> +     CheckObjCInstMethSignature.cpp \
> +     FuchsiaHandleChecker.cpp \
> +     MIGChecker.cpp \
> +     MacOSKeychainAPIChecker.cpp \
> +     MacOSXAPIChecker.cpp \
> +     ObjCAtSyncChecker.cpp \
> +     ObjCAutoreleaseWriteChecker.cpp \
> +     ObjCContainersASTChecker.cpp \
> +     ObjCContainersChecker.cpp \
> +     ObjCMissingSuperCallChecker.cpp \
> +     ObjCPropertyChecker.cpp \
> +     ObjCSelfInitChecker.cpp \
> +     ObjCSuperDeallocChecker.cpp \
> +     ObjCUnusedIVarsChecker.cpp \
> +     OSObjectCStyleCast.cpp \
> +     CXXSelfAssignmentChecker.cpp \
> +     ContainerModeling.cpp \
> +     DebugContainerModeling.cpp \
> +     DebugIteratorModeling.cpp \
> +     DeleteWithNonVirtualDtorChecker.cpp \
> +     MPIBugReporter.cpp \
> +     MPIChecker.cpp \
> +     MPIFunctionClassifier.cpp \
> +     RetainCountChecker.cpp \
> +     RetainCountDiagnostics.cpp \
> +     UninitializedObjectChecker.cpp \
> +     UninitializedPointee.cpp \
> +     PutenvWithAutoChecker.cpp \
> +     DirectIvarAssignment.cpp \
> +     MoveChecker.cpp \
> +     LLVMConventionsChecker.cpp \
> +     DynamicTypeChecker.cpp \
> +     DynamicTypePropagation.cpp \
> +     STLAlgorithmModeling.cpp \
> +     SmartPtrChecker.cpp \
> +     EnumCastOutOfRangeChecker.cpp \
> +     GCDAntipatternChecker.cpp \
> +     NoUncountedMembersChecker.cpp \
> +     RefCntblBaseVirtualDtorChecker.cpp \
> +     UncountedCallArgsChecker.cpp \
> +     UncountedLambdaCapturesChecker.cpp \
> +     UncountedLocalVarsChecker.cpp \
> +     PtrTypesSemantics.cpp \
> +     GTestChecker.cpp \
> +     IteratorModeling.cpp \
> +     Iterator.cpp \
> +     IteratorRangeChecker.cpp \
> +     CheckPlacementNew.cpp \
> +     ASTUtils.cpp \
> +     UncountedCallArgsChecker.cpp \
> +     SmartPtrModeling.cpp \
> +
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Checkers
> +.PATH:       
> ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Checkers/MPI-Checker
> +.PATH:       
> ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Checkers/UninitializedObject
> +.PATH:       
> ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker
> +.PATH:       
> ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Checkers/WebKit
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Checkers/cert
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Core
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/StaticAnalyzer/Frontend
> +
> +install:
> +     @# Nothing here so far ...
> +
> +.include <bsd.lib.mk>
> diff --git gnu/usr.bin/clang/libclangTooling/Makefile 
> gnu/usr.bin/clang/libclangTooling/Makefile
> new file mode 100644
> index 00000000000..bb1aa00b4f9
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangTooling/Makefile
> @@ -0,0 +1,20 @@
> +LIB= clangTooling
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=   -I ${.CURDIR}/../../../llvm/clang/lib/Tooling
> +CPPFLAGS+=    ${CLANG_INCLUDES}
> +
> +.include <bsd.own.mk>
> +
> +SRCS+=       Refactoring.cpp \
> +     Replacement.cpp \
> +
> +
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/Tooling/
> +.PATH:       ${.CURDIR}/../../../llvm/clang/lib/Tooling/Core/
> +
> +install:
> +     @# Nothing here so far ...
> +
> +.include <bsd.lib.mk>
> 

Hi,

I agree and think the sanitizer (-fsanitize) can be useful too:
https://clang.llvm.org/docs/UsersManual.html#id42

-- 
Kind regards,
Hiltjo

Reply via email to