Skip to content

Commit 9ee6dc1

Browse files
authored
Merge branch 'main' into ir2vec
2 parents affbabe + 7c5b535 commit 9ee6dc1

File tree

95 files changed

+7021
-2789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+7021
-2789
lines changed

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ Improvements to clang-tidy
126126
- Improved :program:`clang-tidy` option `-quiet` by suppressing diagnostic
127127
count messages.
128128

129+
- Improved :program:`clang-tidy` by not crashing when an empty `directory`
130+
field is used in a compilation database; the current working directory
131+
will be used instead, and an error message will be printed.
132+
129133
New checks
130134
^^^^^^^^^^
131135

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[{
2+
"directory":"/invalid/",
3+
"file":"/tmp/",
4+
"arguments": []
5+
}]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// UNSUPPORTED: system-windows
22

3-
// RUN: not --crash clang-tidy -p %S/Inputs/empty-database %s 2>&1 | FileCheck %s
3+
// RUN: clang-tidy -p %S/Inputs/empty-database %s 2>&1 | FileCheck %s
44

5-
// CHECK: LLVM ERROR: Cannot chdir into ""!
5+
// CHECK: 'directory' field of compilation database is empty; using the current working directory instead.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// UNSUPPORTED: system-windows
2+
3+
// RUN: not --crash clang-tidy -p %S/Inputs/invalid-database %s 2>&1 | FileCheck %s
4+
5+
// CHECK: LLVM ERROR: Cannot chdir into "/invalid/"!

clang/include/clang/Analysis/FlowSensitive/StorageLocation.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "clang/AST/Decl.h"
1818
#include "clang/AST/Type.h"
1919
#include "llvm/ADT/DenseMap.h"
20-
#include "llvm/ADT/StringRef.h"
2120
#include "llvm/Support/Debug.h"
2221
#include <cassert>
2322

@@ -153,11 +152,6 @@ class RecordStorageLocation final : public StorageLocation {
153152
return {SyntheticFields.begin(), SyntheticFields.end()};
154153
}
155154

156-
/// Add a synthetic field, if none by that name is already present.
157-
void addSyntheticField(llvm::StringRef Name, StorageLocation &Loc) {
158-
SyntheticFields.insert({Name, &Loc});
159-
}
160-
161155
/// Changes the child storage location for a field `D` of reference type.
162156
/// All other fields cannot change their storage location and always retain
163157
/// the storage location passed to the `RecordStorageLocation` constructor.
@@ -170,11 +164,6 @@ class RecordStorageLocation final : public StorageLocation {
170164
Children[&D] = Loc;
171165
}
172166

173-
/// Add a child storage location for a field `D`, if not already present.
174-
void addChild(const ValueDecl &D, StorageLocation *Loc) {
175-
Children.insert({&D, Loc});
176-
}
177-
178167
llvm::iterator_range<FieldToLoc::const_iterator> children() const {
179168
return {Children.begin(), Children.end()};
180169
}

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ let Features = "sse4.1", Attributes = [NoThrow, Const, RequiredVectorWidth<128>]
315315
def pblendw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>, _Constant int)">;
316316
def blendpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, double>, _Constant int)">;
317317
def blendps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Constant int)">;
318-
def blendvpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, double>, _Vector<2, double>)">;
319-
def blendvps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Vector<4, float>)">;
320318
def packusdw128 : X86Builtin<"_Vector<8, short>(_Vector<4, int>, _Vector<4, int>)">;
321319
def roundps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Constant int)">;
322320
def roundss : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Constant int)">;
@@ -335,7 +333,10 @@ let Features = "sse4.1", Attributes = [NoThrow, Const, RequiredVectorWidth<128>]
335333
}
336334

337335
let Features = "sse4.1", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
336+
def blendvpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, double>, _Vector<2, double>)">;
337+
def blendvps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Vector<4, float>)">;
338338
def pblendvb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>, _Vector<16, char>)">;
339+
339340
def pmuldq128 : X86Builtin<"_Vector<2, long long int>(_Vector<4, int>, _Vector<4, int>)">;
340341
}
341342

@@ -470,8 +471,6 @@ let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in
470471
def vpermilvarps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, int>)">;
471472
def blendpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Constant int)">;
472473
def blendps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant int)">;
473-
def blendvpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Vector<4, double>)">;
474-
def blendvps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Vector<8, float>)">;
475474
def shufpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Constant int)">;
476475
def shufps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant int)">;
477476
def dpps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant char)">;
@@ -495,6 +494,11 @@ let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in
495494
def vpermilps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Constant int)">;
496495
}
497496

497+
let Features = "avx", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<256>] in {
498+
def blendvpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Vector<4, double>)">;
499+
def blendvps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Vector<8, float>)">;
500+
}
501+
498502
let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
499503
def vpermilpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Constant int)">;
500504
def vpermilps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Constant int)">;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,6 +3421,15 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
34213421
return F;
34223422
});
34233423

3424+
case clang::X86::BI__builtin_ia32_blendvpd:
3425+
case clang::X86::BI__builtin_ia32_blendvpd256:
3426+
case clang::X86::BI__builtin_ia32_blendvps:
3427+
case clang::X86::BI__builtin_ia32_blendvps256:
3428+
return interp__builtin_elementwise_triop_fp(
3429+
S, OpPC, Call,
3430+
[](const APFloat &F, const APFloat &T, const APFloat &C,
3431+
llvm::RoundingMode) { return C.isNegative() ? T : F; });
3432+
34243433
case clang::X86::BI__builtin_ia32_pblendvb128:
34253434
case clang::X86::BI__builtin_ia32_pblendvb256:
34263435
return interp__builtin_elementwise_triop(

clang/lib/AST/ExprConstant.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11995,6 +11995,10 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1199511995

1199611996
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
1199711997
}
11998+
case X86::BI__builtin_ia32_blendvpd:
11999+
case X86::BI__builtin_ia32_blendvpd256:
12000+
case X86::BI__builtin_ia32_blendvps:
12001+
case X86::BI__builtin_ia32_blendvps256:
1199812002
case X86::BI__builtin_ia32_pblendvb128:
1199912003
case X86::BI__builtin_ia32_pblendvb256: {
1200012004
// SSE blendv by mask signbit: "Result = C[] < 0 ? T[] : F[]".
@@ -12011,8 +12015,9 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1201112015
for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
1201212016
const APValue &F = SourceF.getVectorElt(EltNum);
1201312017
const APValue &T = SourceT.getVectorElt(EltNum);
12014-
APInt C = SourceC.getVectorElt(EltNum).getInt();
12015-
ResultElements.push_back(C.isNegative() ? T : F);
12018+
const APValue &C = SourceC.getVectorElt(EltNum);
12019+
APInt M = C.isInt() ? (APInt)C.getInt() : C.getFloat().bitcastToAPInt();
12020+
ResultElements.push_back(M.isNegative() ? T : F);
1201612021
}
1201712022

1201812023
return Success(APValue(ResultElements.data(), ResultElements.size()), E);

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@
2020
#include "clang/AST/OperationKinds.h"
2121
#include "clang/AST/Stmt.h"
2222
#include "clang/AST/StmtVisitor.h"
23-
#include "clang/AST/Type.h"
2423
#include "clang/Analysis/FlowSensitive/ASTOps.h"
2524
#include "clang/Analysis/FlowSensitive/AdornedCFG.h"
2625
#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
2726
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
2827
#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
2928
#include "clang/Analysis/FlowSensitive/RecordOps.h"
30-
#include "clang/Analysis/FlowSensitive/StorageLocation.h"
3129
#include "clang/Analysis/FlowSensitive/Value.h"
3230
#include "clang/Basic/Builtins.h"
33-
#include "clang/Basic/LLVM.h"
3431
#include "clang/Basic/OperatorKinds.h"
3532
#include "llvm/Support/Casting.h"
3633
#include <assert.h>
@@ -290,7 +287,7 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
290287
}
291288
}
292289

293-
void VisitCastExpr(const CastExpr *S) {
290+
void VisitImplicitCastExpr(const ImplicitCastExpr *S) {
294291
const Expr *SubExpr = S->getSubExpr();
295292
assert(SubExpr != nullptr);
296293

@@ -320,70 +317,17 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
320317
break;
321318
}
322319

323-
case CK_BaseToDerived: {
324-
// This is a cast of (single-layer) pointer or reference to a record type.
325-
// We should now model the fields for the derived type.
326-
327-
// Get the RecordStorageLocation for the record object underneath.
328-
RecordStorageLocation *Loc = nullptr;
329-
if (S->getType()->isPointerType()) {
330-
auto *PV = Env.get<PointerValue>(*SubExpr);
331-
assert(PV != nullptr);
332-
if (PV == nullptr)
333-
break;
334-
Loc = cast<RecordStorageLocation>(&PV->getPointeeLoc());
335-
} else {
336-
assert(S->getType()->isRecordType());
337-
if (SubExpr->isGLValue()) {
338-
Loc = Env.get<RecordStorageLocation>(*SubExpr);
339-
} else {
340-
Loc = &Env.getResultObjectLocation(*SubExpr);
341-
}
342-
}
343-
if (!Loc) {
344-
// Nowhere to add children or propagate from, so we're done.
345-
break;
346-
}
347-
348-
// Get the derived record type underneath the reference or pointer.
349-
QualType Derived = S->getType().getNonReferenceType();
350-
if (Derived->isPointerType()) {
351-
Derived = Derived->getPointeeType();
352-
}
353-
354-
// Add children to the storage location for fields (including synthetic
355-
// fields) of the derived type and initialize their values.
356-
for (const FieldDecl *Field :
357-
Env.getDataflowAnalysisContext().getModeledFields(Derived)) {
358-
assert(Field != nullptr);
359-
QualType FieldType = Field->getType();
360-
if (FieldType->isReferenceType()) {
361-
Loc->addChild(*Field, nullptr);
362-
} else {
363-
Loc->addChild(*Field, &Env.createStorageLocation(FieldType));
364-
}
365-
366-
for (const auto &Entry :
367-
Env.getDataflowAnalysisContext().getSyntheticFields(Derived)) {
368-
Loc->addSyntheticField(Entry.getKey(),
369-
Env.createStorageLocation(Entry.getValue()));
370-
}
371-
}
372-
Env.initializeFieldsWithValues(*Loc, Derived);
373-
374-
// Fall through to propagate SubExpr's StorageLocation to the CastExpr.
375-
[[fallthrough]];
376-
}
377320
case CK_IntegralCast:
378321
// FIXME: This cast creates a new integral value from the
379322
// subexpression. But, because we don't model integers, we don't
380323
// distinguish between this new value and the underlying one. If integer
381324
// modeling is added, then update this code to create a fresh location and
382325
// value.
383326
case CK_UncheckedDerivedToBase:
384-
case CK_DerivedToBase:
385327
case CK_ConstructorConversion:
386328
case CK_UserDefinedConversion:
329+
// FIXME: Add tests that excercise CK_UncheckedDerivedToBase,
330+
// CK_ConstructorConversion, and CK_UserDefinedConversion.
387331
case CK_NoOp: {
388332
// FIXME: Consider making `Environment::getStorageLocation` skip noop
389333
// expressions (this and other similar expressions in the file) instead
@@ -740,6 +684,15 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
740684
propagateValue(*SubExpr, *S, Env);
741685
}
742686

687+
void VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
688+
if (S->getCastKind() == CK_NoOp) {
689+
const Expr *SubExpr = S->getSubExpr();
690+
assert(SubExpr != nullptr);
691+
692+
propagateValueOrStorageLocation(*SubExpr, *S, Env);
693+
}
694+
}
695+
743696
void VisitConditionalOperator(const ConditionalOperator *S) {
744697
const Environment *TrueEnv = StmtToEnv.getEnvironment(*S->getTrueExpr());
745698
const Environment *FalseEnv = StmtToEnv.getEnvironment(*S->getFalseExpr());

0 commit comments

Comments
 (0)