Skip to content

Commit

Permalink
Merged master:e1741e34e00 into amd-gfx:da89f3bc942
Browse files Browse the repository at this point in the history
Local branch amd-gfx da89f3b [AMDGPU] Temporary fix to get previous intrinsic cost
Remote branch master e1741e3 [analyzer] Reasoning about comparison expressions in RangeConstraintManager
  • Loading branch information
Sw authored and Sw committed Jun 15, 2020
2 parents da89f3b + e1741e3 commit 6618d61
Show file tree
Hide file tree
Showing 183 changed files with 17,394 additions and 12,786 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
// RUN: clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' -export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
// RUN: not clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' -export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s -implicit-check-not='{{warning|error|note}}:'
// RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
#define X(n) void n ## n() {}
X(f)
int a[-1];

// CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 'ff' [clang-diagnostic-missing-prototypes]
// CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
// CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
// CHECK-MESSAGES: -input.cpp:2:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
// CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X'
// CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a negative size [clang-diagnostic-error]

// CHECK-YAML: ---
// CHECK-YAML-NEXT: MainSourceFile: '{{.*}}-input.cpp'
Expand Down Expand Up @@ -42,4 +44,18 @@ X(f)
// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
// CHECK-YAML-NEXT: FileOffset: 13
// CHECK-YAML-NEXT: Replacements: []
// CHECK-YAML-NEXT: Level: Warning
// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error
// CHECK-YAML-NEXT: DiagnosticMessage:
// CHECK-YAML-NEXT: Message: '''a'' declared as an array with a negative size'
// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
// CHECK-YAML-NEXT: FileOffset: 41
// CHECK-YAML-NEXT: Replacements: []
// CHECK-YAML-NEXT: Level: Error
// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
// CHECK-YAML-NEXT: Ranges:
// CHECK-YAML-NEXT: - FilePath: '{{.*}}-input.cpp'
// CHECK-YAML-NEXT: FileOffset: 41
// CHECK-YAML-NEXT: Length: 1
// CHECK-YAML-NEXT: ...
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -7948,6 +7948,9 @@ def err_overflow_builtin_must_be_int : Error<
def err_overflow_builtin_must_be_ptr_int : Error<
"result argument to overflow builtin must be a pointer "
"to a non-const integer (%0 invalid)">;
def err_overflow_builtin_ext_int_max_size : Error<
"__builtin_mul_overflow does not support signed _ExtInt operands of more "
"than %0 bits">;

def err_atomic_load_store_uses_lib : Error<
"atomic %select{load|store}0 requires runtime support that is not "
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ class Sema final {
/// we won't know until all lvalue-to-rvalue and discarded value conversions
/// have been applied to all subexpressions of the enclosing full expression.
/// This is cleared at the end of each full expression.
using MaybeODRUseExprSet = llvm::SmallSetVector<Expr *, 2>;
using MaybeODRUseExprSet = llvm::SetVector<Expr *, SmallVector<Expr *, 4>,
llvm::SmallPtrSet<Expr *, 4>>;
MaybeODRUseExprSet MaybeODRUseExprs;

std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope;
Expand Down
13 changes: 10 additions & 3 deletions clang/include/clang/Tooling/DiagnosticsYaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ template <> struct MappingTraits<clang::tooling::Diagnostic> {

std::string DiagnosticName;
clang::tooling::DiagnosticMessage Message;
llvm::StringMap<clang::tooling::Replacements> Fix;
SmallVector<clang::tooling::DiagnosticMessage, 1> Notes;
clang::tooling::Diagnostic::Level DiagLevel;
std::string BuildDirectory;
Expand All @@ -90,9 +89,9 @@ template <> struct MappingTraits<clang::tooling::Diagnostic> {
Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
Io.mapRequired("DiagnosticMessage", Keys->Message);
Io.mapOptional("Notes", Keys->Notes);
Io.mapOptional("Level", Keys->DiagLevel);
Io.mapOptional("BuildDirectory", Keys->BuildDirectory);
Io.mapOptional("Ranges", Keys->Ranges);

// FIXME: Export properly all the different fields.
}
};

Expand All @@ -104,6 +103,14 @@ template <> struct MappingTraits<clang::tooling::TranslationUnitDiagnostics> {
Io.mapRequired("Diagnostics", Doc.Diagnostics);
}
};

template <> struct ScalarEnumerationTraits<clang::tooling::Diagnostic::Level> {
static void enumeration(IO &IO, clang::tooling::Diagnostic::Level &Value) {
IO.enumCase(Value, "Warning", clang::tooling::Diagnostic::Warning);
IO.enumCase(Value, "Error", clang::tooling::Diagnostic::Error);
}
};

} // end namespace yaml
} // end namespace llvm

Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ void ConstantExpr::DefaultInit(ResultStorageKind StorageKind) {
ConstantExprBits.ResultKind = StorageKind;
ConstantExprBits.APValueKind = APValue::None;
ConstantExprBits.HasCleanup = false;
ConstantExprBits.IsImmediateInvocation = false;
if (StorageKind == ConstantExpr::RSK_APValue)
::new (getTrailingObjects<APValue>()) APValue();
}
Expand Down
9 changes: 0 additions & 9 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9986,8 +9986,6 @@ class IntExprEvaluator
// Visitor Methods
//===--------------------------------------------------------------------===//

bool VisitConstantExpr(const ConstantExpr *E);

bool VisitIntegerLiteral(const IntegerLiteral *E) {
return Success(E->getValue(), E);
}
Expand Down Expand Up @@ -10769,13 +10767,6 @@ static bool tryEvaluateBuiltinObjectSize(const Expr *E, unsigned Type,
return true;
}

bool IntExprEvaluator::VisitConstantExpr(const ConstantExpr *E) {
llvm::SaveAndRestore<bool> InConstantContext(Info.InConstantContext, true);
if (E->getResultAPValueKind() != APValue::None)
return Success(E->getAPValueResult(), E);
return ExprEvaluatorBaseTy::VisitConstantExpr(E);
}

bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
if (unsigned BuiltinOp = E->getBuiltinCallee())
return VisitBuiltinCallExpr(E, BuiltinOp);
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ static WidthAndSignedness
getIntegerWidthAndSignedness(const clang::ASTContext &context,
const clang::QualType Type) {
assert(Type->isIntegerType() && "Given type is not an integer.");
unsigned Width = Type->isBooleanType() ? 1 : context.getTypeInfo(Type).Width;
unsigned Width = Type->isBooleanType() ? 1
: Type->isExtIntType() ? context.getIntWidth(Type)
: context.getTypeInfo(Type).Width;
bool Signed = Type->isSignedIntegerType();
return {Width, Signed};
}
Expand Down
19 changes: 9 additions & 10 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,18 +1272,17 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
// store the elements rather than the aggregate to be more friendly to
// fast-isel.
// FIXME: Do we need to recurse here?
static void BuildAggStore(CodeGenFunction &CGF, llvm::Value *Val,
Address Dest, bool DestIsVolatile) {
void CodeGenFunction::EmitAggregateStore(llvm::Value *Val, Address Dest,
bool DestIsVolatile) {
// Prefer scalar stores to first-class aggregate stores.
if (llvm::StructType *STy =
dyn_cast<llvm::StructType>(Val->getType())) {
if (llvm::StructType *STy = dyn_cast<llvm::StructType>(Val->getType())) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
Address EltPtr = CGF.Builder.CreateStructGEP(Dest, i);
llvm::Value *Elt = CGF.Builder.CreateExtractValue(Val, i);
CGF.Builder.CreateStore(Elt, EltPtr, DestIsVolatile);
Address EltPtr = Builder.CreateStructGEP(Dest, i);
llvm::Value *Elt = Builder.CreateExtractValue(Val, i);
Builder.CreateStore(Elt, EltPtr, DestIsVolatile);
}
} else {
CGF.Builder.CreateStore(Val, Dest, DestIsVolatile);
Builder.CreateStore(Val, Dest, DestIsVolatile);
}
}

Expand Down Expand Up @@ -1334,7 +1333,7 @@ static void CreateCoercedStore(llvm::Value *Src,
// If store is legal, just bitcast the src pointer.
if (SrcSize <= DstSize) {
Dst = CGF.Builder.CreateElementBitCast(Dst, SrcTy);
BuildAggStore(CGF, Src, Dst, DstIsVolatile);
CGF.EmitAggregateStore(Src, Dst, DstIsVolatile);
} else {
// Otherwise do coercion through memory. This is stupid, but
// simple.
Expand Down Expand Up @@ -5070,7 +5069,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
DestPtr = CreateMemTemp(RetTy, "agg.tmp");
DestIsVolatile = false;
}
BuildAggStore(*this, CI, DestPtr, DestIsVolatile);
EmitAggregateStore(CI, DestPtr, DestIsVolatile);
return RValue::getAggregate(DestPtr);
}
case TEK_Scalar: {
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,8 @@ void CodeGenFunction::EmitScalarInit(const Expr *init, const ValueDecl *D,

// If we're emitting a value with lifetime, we have to do the
// initialization *before* we leave the cleanup scopes.
if (const FullExpr *fe = dyn_cast<FullExpr>(init))
init = fe->getSubExpr();

if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(init))
init = EWC->getSubExpr();
CodeGenFunction::RunCleanupsScope Scope(*this);

// We have to maintain the illusion that the variable is
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,15 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
return EmitVAArgExprLValue(cast<VAArgExpr>(E));
case Expr::DeclRefExprClass:
return EmitDeclRefLValue(cast<DeclRefExpr>(E));
case Expr::ConstantExprClass:
case Expr::ConstantExprClass: {
const ConstantExpr *CE = cast<ConstantExpr>(E);
if (llvm::Value *Result = ConstantEmitter(*this).tryEmitConstantExpr(CE)) {
QualType RetType = cast<CallExpr>(CE->getSubExpr()->IgnoreImplicit())
->getCallReturnType(getContext());
return MakeNaturalAlignAddrLValue(Result, RetType);
}
return EmitLValue(cast<ConstantExpr>(E)->getSubExpr());
}
case Expr::ParenExprClass:
return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
case Expr::GenericSelectionExprClass:
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CodeGen/CGExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
}

void VisitConstantExpr(ConstantExpr *E) {
if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
CGF.EmitAggregateStore(Result, Dest.getAddress(),
E->getType().isVolatileQualified());
return;
}
return Visit(E->getSubExpr());
}

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CGExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "CGOpenMPRuntime.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "ConstantEmitter.h"
#include "clang/AST/StmtVisitor.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Constants.h"
Expand Down Expand Up @@ -102,6 +103,9 @@ class ComplexExprEmitter
}
ComplexPairTy VisitExpr(Expr *S);
ComplexPairTy VisitConstantExpr(ConstantExpr *E) {
if (llvm::Constant *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E))
return ComplexPairTy(Result->getAggregateElement(0U),
Result->getAggregateElement(1U));
return Visit(E->getSubExpr());
}
ComplexPairTy VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr());}
Expand Down
18 changes: 18 additions & 0 deletions clang/lib/CodeGen/CGExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,8 @@ class ConstExprEmitter :
}

llvm::Constant *VisitConstantExpr(ConstantExpr *CE, QualType T) {
if (llvm::Constant *Result = Emitter.tryEmitConstantExpr(CE))
return Result;
return Visit(CE->getSubExpr(), T);
}

Expand Down Expand Up @@ -1358,6 +1360,20 @@ ConstantEmitter::tryEmitAbstract(const APValue &value, QualType destType) {
return validateAndPopAbstract(C, state);
}

llvm::Constant *ConstantEmitter::tryEmitConstantExpr(const ConstantExpr *CE) {
if (!CE->hasAPValueResult())
return nullptr;
const Expr *Inner = CE->getSubExpr()->IgnoreImplicit();
QualType RetType;
if (auto *Call = dyn_cast<CallExpr>(Inner))
RetType = Call->getCallReturnType(CGF->getContext());
else if (auto *Ctor = dyn_cast<CXXConstructExpr>(Inner))
RetType = Ctor->getType();
llvm::Constant *Res =
emitAbstract(CE->getBeginLoc(), CE->getAPValueResult(), RetType);
return Res;
}

llvm::Constant *
ConstantEmitter::emitAbstract(const Expr *E, QualType destType) {
auto state = pushAbstract();
Expand Down Expand Up @@ -1903,6 +1919,8 @@ ConstantLValueEmitter::tryEmitBase(const APValue::LValueBase &base) {

ConstantLValue
ConstantLValueEmitter::VisitConstantExpr(const ConstantExpr *E) {
if (llvm::Constant *Result = Emitter.tryEmitConstantExpr(E))
return Result;
return Visit(E->getSubExpr());
}

Expand Down
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ class ScalarExprEmitter
Value *VisitExpr(Expr *S);

Value *VisitConstantExpr(ConstantExpr *E) {
if (Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
if (E->isGLValue())
return CGF.Builder.CreateLoad(Address(
Result, CGF.getContext().getTypeAlignInChars(E->getType())));
return Result;
}
return Visit(E->getSubExpr());
}
Value *VisitParenExpr(ParenExpr *PE) {
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,8 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
SaveRetExprRAII SaveRetExpr(RV, *this);

RunCleanupsScope cleanupScope(*this);
if (const FullExpr *fe = dyn_cast_or_null<FullExpr>(RV))
RV = fe->getSubExpr();

if (const auto *EWC = dyn_cast_or_null<ExprWithCleanups>(RV))
RV = EWC->getSubExpr();
// FIXME: Clean this up by using an LValue for ReturnTemp,
// EmitStoreThroughLValue, and EmitAnyExpr.
// Check if the NRVO candidate was not globalized in OpenMP mode.
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4138,6 +4138,10 @@ class CodeGenFunction : public CodeGenTypeCache {
/// aggregate type into a temporary LValue.
LValue EmitAggExprToLValue(const Expr *E);

/// Build all the stores needed to initialize an aggregate at Dest with the
/// value Val.
void EmitAggregateStore(llvm::Value *Val, Address Dest, bool DestIsVolatile);

/// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
/// make sure it survives garbage collection until this point.
void EmitExtendGCLifetime(llvm::Value *object);
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3336,6 +3336,8 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD,
bool ForVTable,
bool DontDefer,
ForDefinition_t IsForDefinition) {
assert(!cast<FunctionDecl>(GD.getDecl())->isConsteval() &&
"consteval function should never be emitted");
// If there was no specific requested type, just convert it now.
if (!Ty) {
const auto *FD = cast<FunctionDecl>(GD.getDecl());
Expand Down Expand Up @@ -5330,6 +5332,11 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
if (D->isTemplated())
return;

// Consteval function shouldn't be emitted.
if (auto *FD = dyn_cast<FunctionDecl>(D))
if (FD->isConsteval())
return;

switch (D->getKind()) {
case Decl::CXXConversion:
case Decl::CXXMethod:
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/ConstantEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class ConstantEmitter {
llvm::Constant *tryEmitAbstract(const APValue &value, QualType T);
llvm::Constant *tryEmitAbstractForMemory(const APValue &value, QualType T);

llvm::Constant *tryEmitConstantExpr(const ConstantExpr *CE);

llvm::Constant *emitNullForMemory(QualType T) {
return emitNullForMemory(CGM, T);
}
Expand Down
Loading

0 comments on commit 6618d61

Please sign in to comment.