Skip to content

Commit

Permalink
Merge branch amd-master into amd-common
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins committed Jun 20, 2017
2 parents 16f7ddd + a1efca5 commit e74fd5c
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/clang/Analysis/CloneDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ struct OnlyLargestCloneConstraint {
void constrain(std::vector<CloneDetector::CloneGroup> &Result);
};

struct AutoGeneratedCloneConstraint {
struct FilenamePatternConstraint {
StringRef IgnoredFilesPattern;
std::shared_ptr<llvm::Regex> IgnoredFilesRegex;

AutoGeneratedCloneConstraint(StringRef IgnoredFilesPattern)
FilenamePatternConstraint(StringRef IgnoredFilesPattern)
: IgnoredFilesPattern(IgnoredFilesPattern) {
IgnoredFilesRegex = std::make_shared<llvm::Regex>("^(" +
IgnoredFilesPattern.str() + "$)");
Expand Down
4 changes: 3 additions & 1 deletion include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def GNUFlexibleArrayUnionMember : DiagGroup<"gnu-flexible-array-union-member">;
def GNUFoldingConstant : DiagGroup<"gnu-folding-constant">;
def FormatExtraArgs : DiagGroup<"format-extra-args">;
def FormatZeroLength : DiagGroup<"format-zero-length">;
def CXX1zCompatMangling : DiagGroup<"c++1z-compat-mangling">;

// Warnings for C++1y code which is not compatible with prior C++ standards.
def CXXPre14Compat : DiagGroup<"c++98-c++11-compat">;
Expand Down Expand Up @@ -211,7 +212,8 @@ def CXX14CompatPedantic : DiagGroup<"c++14-compat-pedantic",
[CXXPre1zCompatPedantic]>;

def CXX1zCompat : DiagGroup<"c++1z-compat", [DeprecatedRegister,
DeprecatedIncrementBool]>;
DeprecatedIncrementBool,
CXX1zCompatMangling]>;

def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
Expand Down
2 changes: 1 addition & 1 deletion include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def warn_deprecated_copy_operation : Warning<
InGroup<Deprecated>, DefaultIgnore;
def warn_cxx1z_compat_exception_spec_in_signature : Warning<
"mangled name of %0 will change in C++17 due to non-throwing exception "
"specification in function signature">, InGroup<CXX1zCompat>;
"specification in function signature">, InGroup<CXX1zCompatMangling>;

def warn_global_constructor : Warning<
"declaration requires a global constructor">,
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/CloneDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void OnlyLargestCloneConstraint::constrain(
}
}

bool AutoGeneratedCloneConstraint::isAutoGenerated(const CloneDetector::CloneGroup &Group) {
bool FilenamePatternConstraint::isAutoGenerated(const CloneDetector::CloneGroup &Group) {
std::string Error;
if (IgnoredFilesPattern.empty() || Group.empty() ||
!IgnoredFilesRegex->isValid(Error))
Expand Down
51 changes: 51 additions & 0 deletions lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class CStringChecker : public Checker< eval::Call,
void evalStdCopy(CheckerContext &C, const CallExpr *CE) const;
void evalStdCopyBackward(CheckerContext &C, const CallExpr *CE) const;
void evalStdCopyCommon(CheckerContext &C, const CallExpr *CE) const;
void evalMemset(CheckerContext &C, const CallExpr *CE) const;

// Utility methods
std::pair<ProgramStateRef , ProgramStateRef >
Expand Down Expand Up @@ -1999,6 +2000,54 @@ void CStringChecker::evalStdCopyCommon(CheckerContext &C,
C.addTransition(State);
}

void CStringChecker::evalMemset(CheckerContext &C, const CallExpr *CE) const {
if (CE->getNumArgs() != 3)
return;

CurrentFunctionDescription = "memory set function";

const Expr *Mem = CE->getArg(0);
const Expr *Size = CE->getArg(2);
ProgramStateRef State = C.getState();

// See if the size argument is zero.
const LocationContext *LCtx = C.getLocationContext();
SVal SizeVal = State->getSVal(Size, LCtx);
QualType SizeTy = Size->getType();

ProgramStateRef StateZeroSize, StateNonZeroSize;
std::tie(StateZeroSize, StateNonZeroSize) =
assumeZero(C, State, SizeVal, SizeTy);

// Get the value of the memory area.
SVal MemVal = State->getSVal(Mem, LCtx);

// If the size is zero, there won't be any actual memory access, so
// just bind the return value to the Mem buffer and return.
if (StateZeroSize && !StateNonZeroSize) {
StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, MemVal);
C.addTransition(StateZeroSize);
return;
}

// Ensure the memory area is not null.
// If it is NULL there will be a NULL pointer dereference.
State = checkNonNull(C, StateNonZeroSize, Mem, MemVal);
if (!State)
return;

State = CheckBufferAccess(C, State, Size, Mem);
if (!State)
return;
State = InvalidateBuffer(C, State, Mem, C.getSVal(Mem),
/*IsSourceBuffer*/false, Size);
if (!State)
return;

State = State->BindExpr(CE, LCtx, MemVal);
C.addTransition(State);
}

static bool isCPPStdLibraryFunction(const FunctionDecl *FD, StringRef Name) {
IdentifierInfo *II = FD->getIdentifier();
if (!II)
Expand Down Expand Up @@ -2032,6 +2081,8 @@ bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
evalFunction = &CStringChecker::evalMemcmp;
else if (C.isCLibraryFunction(FDecl, "memmove"))
evalFunction = &CStringChecker::evalMemmove;
else if (C.isCLibraryFunction(FDecl, "memset"))
evalFunction = &CStringChecker::evalMemset;
else if (C.isCLibraryFunction(FDecl, "strcpy"))
evalFunction = &CStringChecker::evalStrcpy;
else if (C.isCLibraryFunction(FDecl, "strncpy"))
Expand Down
2 changes: 1 addition & 1 deletion lib/StaticAnalyzer/Checkers/CloneChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void CloneChecker::checkEndOfTranslationUnit(const TranslationUnitDecl *TU,
std::vector<CloneDetector::CloneGroup> AllCloneGroups;

Detector.findClones(AllCloneGroups,
AutoGeneratedCloneConstraint(IgnoredFilesPattern),
FilenamePatternConstraint(IgnoredFilesPattern),
RecursiveCloneTypeIIConstraint(),
MinComplexityConstraint(MinComplexity),
MinGroupSizeConstraint(2), OnlyLargestCloneConstraint());
Expand Down
61 changes: 59 additions & 2 deletions test/Analysis/null-deref-ps-region.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-store=region -verify %s
// expected-no-diagnostics
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,unix,alpha.unix -std=gnu99 -analyzer-store=region -verify %s

#include "Inputs/system-header-simulator.h"

typedef __typeof(sizeof(int)) size_t;
void *memset(void *__s, int __c, size_t __n);
void *malloc(size_t __size);
void free(void *__ptr);

// The store for 'a[1]' should not be removed mistakenly. SymbolicRegions may
// also be live roots.
Expand All @@ -13,3 +18,55 @@ void f14(int *a) {
i = *p; // no-warning
}
}

void foo() {
int *x = malloc(sizeof(int));
memset(x, 0, sizeof(int));
int n = 1 / *x; // FIXME: no-warning
free(x);
}

void bar() {
int *x = malloc(sizeof(int));
memset(x, 0, 1);
int n = 1 / *x; // no-warning
free(x);
}

void testConcreteNull() {
int *x = 0;
memset(x, 0, 1); // expected-warning {{Null pointer argument in call to memory set function}}
}

void testStackArray() {
char buf[13];
memset(buf, 0, 1); // no-warning
}

void testHeapSymbol() {
char *buf = (char *)malloc(13);
memset(buf, 0, 1); // no-warning
free(buf);
}

void testStackArrayOutOfBound() {
char buf[1];
memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}}
}

void testHeapSymbolOutOfBound() {
char *buf = (char *)malloc(1);
memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}}
free(buf);
}

void testStackArraySameSize() {
char buf[1];
memset(buf, 0, sizeof(buf)); // no-warning
}

void testHeapSymbolSameSize() {
char *buf = (char *)malloc(1);
memset(buf, 0, 1); // no-warning
free(buf);
}
3 changes: 2 additions & 1 deletion test/SemaCXX/cxx1z-noexcept-function-type.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -std=c++14 -verify -fexceptions -fcxx-exceptions %s
// RUN: %clang_cc1 -std=c++1z -verify -fexceptions -fcxx-exceptions %s -Wno-dynamic-exception-spec
// RUN: %clang_cc1 -std=c++14 -verify -fexceptions -fcxx-exceptions -Wno-c++1z-compat-mangling -DNO_COMPAT_MANGLING %s

#if __cplusplus > 201402L

Expand Down Expand Up @@ -81,7 +82,7 @@ namespace CompatWarning {
auto f5() -> void (*)() throw();
auto f6() -> void (&)() throw();
auto f7() -> void (X::*)() throw();
#if __cplusplus <= 201402L
#if __cplusplus <= 201402L && !defined(NO_COMPAT_MANGLING)
// expected-warning@-8 {{mangled name of 'f1' will change in C++17 due to non-throwing exception specification in function signature}}
// expected-warning@-8 {{mangled name of 'f2' will change in C++17 due to non-throwing exception specification in function signature}}
// expected-warning@-8 {{mangled name of 'f3' will change in C++17 due to non-throwing exception specification in function signature}}
Expand Down

0 comments on commit e74fd5c

Please sign in to comment.