Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (intel#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
sndmitriev committed Oct 21, 2019
2 parents 675ae5c + 1f43ea4 commit 0c0b233
Show file tree
Hide file tree
Showing 447 changed files with 9,566 additions and 3,078 deletions.
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/FileDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Path.h"
Expand Down
8 changes: 8 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ Improvements to Clang's diagnostics
- -Wtautological-compare for self comparisons and
-Wtautological-overlap-compare will now look through member and array
access to determine if two operand expressions are the same.
- -Wtautological-bitwise-compare is a new warning group. This group has the
current warning which diagnoses the tautological comparison of a bitwise
operation and a constant. The group also has the new warning which diagnoses
when a bitwise-or with a non-negative value is converted to a bool, since
that bool will always be true.
- -Wbitwise-conditional-parentheses will warn on operator precedence issues
when mixing bitwise-and (&) and bitwise-or (|) operator with the
conditional operator (?:).
Non-comprehensive list of changes in this release
-------------------------------------------------
Expand Down
29 changes: 21 additions & 8 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,12 @@ class CXXRecordDecl : public RecordDecl {
/// The number of explicit captures in this lambda.
unsigned NumExplicitCaptures : 13;

/// Has known `internal` linkage.
unsigned HasKnownInternalLinkage : 1;

/// The number used to indicate this lambda expression for name
/// mangling in the Itanium C++ ABI.
unsigned ManglingNumber = 0;
unsigned ManglingNumber : 31;

/// The declaration that provides context for this lambda, if the
/// actual DeclContext does not suffice. This is used for lambdas that
Expand All @@ -406,12 +409,12 @@ class CXXRecordDecl : public RecordDecl {
/// The type of the call method.
TypeSourceInfo *MethodTyInfo;

LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info,
bool Dependent, bool IsGeneric,
LambdaCaptureDefault CaptureDefault)
: DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0),
MethodTyInfo(Info) {
LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent,
bool IsGeneric, LambdaCaptureDefault CaptureDefault)
: DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
CaptureDefault(CaptureDefault), NumCaptures(0),
NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0),
MethodTyInfo(Info) {
IsLambda = true;

// C++1z [expr.prim.lambda]p4:
Expand Down Expand Up @@ -1705,6 +1708,13 @@ class CXXRecordDecl : public RecordDecl {
return getLambdaData().ManglingNumber;
}

/// The lambda is known to has internal linkage no matter whether it has name
/// mangling number.
bool hasKnownLambdaInternalLinkage() const {
assert(isLambda() && "Not a lambda closure type!");
return getLambdaData().HasKnownInternalLinkage;
}

/// Retrieve the declaration that provides additional context for a
/// lambda, when the normal declaration context is not specific enough.
///
Expand All @@ -1718,9 +1728,12 @@ class CXXRecordDecl : public RecordDecl {

/// Set the mangling number and context declaration for a lambda
/// class.
void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl,
bool HasKnownInternalLinkage = false) {
assert(isLambda() && "Not a lambda closure type!");
getLambdaData().ManglingNumber = ManglingNumber;
getLambdaData().ContextDecl = ContextDecl;
getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage;
}

/// Returns the inheritance model used for this record.
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ class CUDAKernelCallExpr final : public CallExpr {
/// - <tt>a != b</tt> -> <tt>!(a == b)</tt>
/// - <tt>a != b</tt> -> <tt>!(b == a)</tt>
/// - For \c \@ in \c <, \c <=, \c >, \c >=, \c <=>:
/// - <tt>a @ b<tt> -> <tt>(a <=> b) @ 0</tt>
/// - <tt>a @ b<tt> -> <tt>0 @ (b <=> a)</tt>
/// - <tt>a @ b</tt> -> <tt>(a <=> b) @ 0</tt>
/// - <tt>a @ b</tt> -> <tt>0 @ (b <=> a)</tt>
///
/// This expression provides access to both the original syntax and the
/// rewritten expression.
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Analysis/CFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ class CFGCallback {
virtual void compareAlwaysTrue(const BinaryOperator *B, bool isAlwaysTrue) {}
virtual void compareBitwiseEquality(const BinaryOperator *B,
bool isAlwaysTrue) {}
virtual void compareBitwiseOr(const BinaryOperator *B) {}
};

/// Represents a source-level, intra-procedural CFG that represents the
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
def FourByteMultiChar : DiagGroup<"four-char-constants">;
def GlobalConstructors : DiagGroup<"global-constructors">;
def BitwiseConditionalParentheses: DiagGroup<"bitwise-conditional-parentheses">;
def BitwiseOpParentheses: DiagGroup<"bitwise-op-parentheses">;
def LogicalOpParentheses: DiagGroup<"logical-op-parentheses">;
def LogicalNotParentheses: DiagGroup<"logical-not-parentheses">;
Expand Down Expand Up @@ -516,12 +517,14 @@ def TautologicalConstantCompare : DiagGroup<"tautological-constant-compare",
[TautologicalOutOfRangeCompare]>;
def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
def TautologicalBitwiseCompare : DiagGroup<"tautological-bitwise-compare">;
def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
def TautologicalObjCBoolCompare : DiagGroup<"tautological-objc-bool-compare">;
def TautologicalCompare : DiagGroup<"tautological-compare",
[TautologicalConstantCompare,
TautologicalPointerCompare,
TautologicalOverlapCompare,
TautologicalBitwiseCompare,
TautologicalUndefinedCompare,
TautologicalObjCBoolCompare]>;
def HeaderHygiene : DiagGroup<"header-hygiene">;
Expand Down Expand Up @@ -735,6 +738,7 @@ def ParenthesesOnEquality : DiagGroup<"parentheses-equality">;
def Parentheses : DiagGroup<"parentheses",
[LogicalOpParentheses,
LogicalNotParentheses,
BitwiseConditionalParentheses,
BitwiseOpParentheses,
ShiftOpParentheses,
OverloadedShiftOpParentheses,
Expand Down
8 changes: 7 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -5771,6 +5771,9 @@ def note_precedence_silence : Note<
def warn_precedence_conditional : Warning<
"operator '?:' has lower precedence than '%0'; '%0' will be evaluated first">,
InGroup<Parentheses>;
def warn_precedence_bitwise_conditional : Warning<
"operator '?:' has lower precedence than '%0'; '%0' will be evaluated first">,
InGroup<BitwiseConditionalParentheses>;
def note_precedence_conditional_first : Note<
"place parentheses around the '?:' expression to evaluate it first">;

Expand Down Expand Up @@ -8358,7 +8361,10 @@ def warn_comparison_always : Warning<
InGroup<TautologicalCompare>;
def warn_comparison_bitwise_always : Warning<
"bitwise comparison always evaluates to %select{false|true}0">,
InGroup<TautologicalCompare>;
InGroup<TautologicalBitwiseCompare>, DefaultIgnore;
def warn_comparison_bitwise_or : Warning<
"bitwise or with non-zero value always evaluates to true">,
InGroup<TautologicalBitwiseCompare>, DefaultIgnore;
def warn_tautological_overlap_comparison : Warning<
"overlapping comparisons always evaluate to %select{false|true}0">,
InGroup<TautologicalOverlapCompare>, DefaultIgnore;
Expand Down
27 changes: 16 additions & 11 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -6056,12 +6056,17 @@ class Sema {
LambdaCaptureDefault CaptureDefault);

/// Start the definition of a lambda expression.
CXXMethodDecl *
startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange,
TypeSourceInfo *MethodType, SourceLocation EndLoc,
ArrayRef<ParmVarDecl *> Params,
ConstexprSpecKind ConstexprKind,
Optional<std::pair<unsigned, Decl *>> Mangling = None);
CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class,
SourceRange IntroducerRange,
TypeSourceInfo *MethodType,
SourceLocation EndLoc,
ArrayRef<ParmVarDecl *> Params,
ConstexprSpecKind ConstexprKind);

/// Number lambda for linkage purposes if necessary.
void handleLambdaNumbering(
CXXRecordDecl *Class, CXXMethodDecl *Method,
Optional<std::tuple<unsigned, bool, Decl *>> Mangling = None);

/// Endow the lambda scope info with the relevant properties.
void buildLambdaScope(sema::LambdaScopeInfo *LSI,
Expand Down Expand Up @@ -10553,11 +10558,11 @@ class Sema {
Ref_Compatible
};

ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
QualType T1, QualType T2,
bool &DerivedToBase,
bool &ObjCConversion,
bool &ObjCLifetimeConversion);
ReferenceCompareResult
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
bool &DerivedToBase, bool &ObjCConversion,
bool &ObjCLifetimeConversion,
bool &FunctionConversion);

ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
Expr *CastExpr, CastKind &CastKind,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,8 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl());
if (!CDeclOrErr)
return CDeclOrErr.takeError();
D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr);
D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr,
DCXX->hasKnownLambdaInternalLinkage());
} else if (DCXX->isInjectedClassName()) {
// We have to be careful to do a similar dance to the one in
// Sema::ActOnStartCXXMemberDeclarations
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,8 @@ LinkageInfo LinkageComputer::computeLVForDecl(const NamedDecl *D,
case Decl::CXXRecord: {
const auto *Record = cast<CXXRecordDecl>(D);
if (Record->isLambda()) {
if (!Record->getLambdaManglingNumber()) {
if (Record->hasKnownLambdaInternalLinkage() ||
!Record->getLambdaManglingNumber()) {
// This lambda has no mangling number, so it's internal.
return getInternalLinkageFor(D);
}
Expand All @@ -1402,7 +1403,8 @@ LinkageInfo LinkageComputer::computeLVForDecl(const NamedDecl *D,
// };
const CXXRecordDecl *OuterMostLambda =
getOutermostEnclosingLambda(Record);
if (!OuterMostLambda->getLambdaManglingNumber())
if (OuterMostLambda->hasKnownLambdaInternalLinkage() ||
!OuterMostLambda->getLambdaManglingNumber())
return getInternalLinkageFor(D);

return getLVForClosure(
Expand Down
41 changes: 40 additions & 1 deletion clang/lib/Analysis/CFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,31 @@ class CFGBuilder {
return {};
}

/// A bitwise-or with a non-zero constant always evaluates to true.
TryResult checkIncorrectBitwiseOrOperator(const BinaryOperator *B) {
const Expr *LHSConstant =
tryTransformToIntOrEnumConstant(B->getLHS()->IgnoreParenImpCasts());
const Expr *RHSConstant =
tryTransformToIntOrEnumConstant(B->getRHS()->IgnoreParenImpCasts());

if ((LHSConstant && RHSConstant) || (!LHSConstant && !RHSConstant))
return {};

const Expr *Constant = LHSConstant ? LHSConstant : RHSConstant;

Expr::EvalResult Result;
if (!Constant->EvaluateAsInt(Result, *Context))
return {};

if (Result.Val.getInt() == 0)
return {};

if (BuildOpts.Observer)
BuildOpts.Observer->compareBitwiseOr(B);

return TryResult(true);
}

/// Try and evaluate an expression to an integer constant.
bool tryEvaluate(Expr *S, Expr::EvalResult &outResult) {
if (!BuildOpts.PruneTriviallyFalseEdges)
Expand All @@ -1156,7 +1181,7 @@ class CFGBuilder {
return {};

if (BinaryOperator *Bop = dyn_cast<BinaryOperator>(S)) {
if (Bop->isLogicalOp()) {
if (Bop->isLogicalOp() || Bop->isEqualityOp()) {
// Check the cache first.
CachedBoolEvalsTy::iterator I = CachedBoolEvals.find(S);
if (I != CachedBoolEvals.end())
Expand Down Expand Up @@ -1240,6 +1265,10 @@ class CFGBuilder {
TryResult BopRes = checkIncorrectRelationalOperator(Bop);
if (BopRes.isKnown())
return BopRes.isTrue();
} else if (Bop->getOpcode() == BO_Or) {
TryResult BopRes = checkIncorrectBitwiseOrOperator(Bop);
if (BopRes.isKnown())
return BopRes.isTrue();
}
}

Expand Down Expand Up @@ -2340,6 +2369,9 @@ CFGBlock *CFGBuilder::VisitUnaryOperator(UnaryOperator *U,
appendStmt(Block, U);
}

if (U->getOpcode() == UO_LNot)
tryEvaluateBool(U->getSubExpr()->IgnoreParens());

return Visit(U->getSubExpr(), AddStmtChoice());
}

Expand Down Expand Up @@ -2474,6 +2506,9 @@ CFGBlock *CFGBuilder::VisitBinaryOperator(BinaryOperator *B,
appendStmt(Block, B);
}

if (B->isEqualityOp() || B->isRelationalOp())
tryEvaluateBool(B);

CFGBlock *RBlock = Visit(B->getRHS());
CFGBlock *LBlock = Visit(B->getLHS());
// If visiting RHS causes us to finish 'Block', e.g. the RHS is a StmtExpr
Expand Down Expand Up @@ -4527,6 +4562,10 @@ CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E,
autoCreateBlock();
appendStmt(Block, E);
}

if (E->getCastKind() == CK_IntegralToBoolean)
tryEvaluateBool(E->getSubExpr()->IgnoreParens());

return Visit(E->getSubExpr(), AddStmtChoice());
}

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,11 @@ void CGDebugInfo::CreateCompileUnit() {
// file to determine the real absolute path for the file.
std::string MainFileDir;
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
MainFileDir = remapDIPath(MainFile->getDir()->getName());
if (MainFileDir != ".") {
MainFileDir = MainFile->getDir()->getName();
if (!llvm::sys::path::is_absolute(MainFileName)) {
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
llvm::sys::path::append(MainFileDirSS, MainFileName);
MainFileName = MainFileDirSS.str();
MainFileName = llvm::sys::path::remove_leading_dotslash(MainFileDirSS);
}
// If the main file name provided is identical to the input file name, and
// if the input file is a preprocessed source, use the module name for
Expand Down
16 changes: 6 additions & 10 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3586,7 +3586,8 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
// Make a new global with the correct type, this is now guaranteed
// to work.
auto *NewGV = cast<llvm::GlobalVariable>(
GetAddrOfGlobalVar(D, InitType, IsForDefinition));
GetAddrOfGlobalVar(D, InitType, IsForDefinition)
->stripPointerCasts());

// Erase the old global, since it is no longer used.
GV->eraseFromParent();
Expand Down Expand Up @@ -4076,14 +4077,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
llvm::Constant *Entry =
GetAddrOfGlobalVar(D, InitType, ForDefinition_t(!IsTentative));

// Strip off a bitcast if we got one back.
if (auto *CE = dyn_cast<llvm::ConstantExpr>(Entry)) {
assert(CE->getOpcode() == llvm::Instruction::BitCast ||
CE->getOpcode() == llvm::Instruction::AddrSpaceCast ||
// All zero index gep.
CE->getOpcode() == llvm::Instruction::GetElementPtr);
Entry = CE->getOperand(0);
}
// Strip off pointer casts if we got them.
Entry = Entry->stripPointerCasts();

// Entry is now either a Function or GlobalVariable.
auto *GV = dyn_cast<llvm::GlobalVariable>(Entry);
Expand All @@ -4106,7 +4101,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,

// Make a new global with the correct type, this is now guaranteed to work.
GV = cast<llvm::GlobalVariable>(
GetAddrOfGlobalVar(D, InitType, ForDefinition_t(!IsTentative)));
GetAddrOfGlobalVar(D, InitType, ForDefinition_t(!IsTentative))
->stripPointerCasts());

// Replace all uses of the old global with the new global
llvm::Constant *NewPtrForOldDecl =
Expand Down
Loading

0 comments on commit 0c0b233

Please sign in to comment.