Skip to content

Commit ec12935

Browse files
committed
merge main into amd-staging
Change-Id: Ic56cba4a2c6579d59b85e64542b44657bb34e158
2 parents dff11dd + 36c1194 commit ec12935

File tree

175 files changed

+2285
-1111
lines changed

Some content is hidden

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

175 files changed

+2285
-1111
lines changed

clang/docs/AddressSanitizer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Typical slowdown introduced by AddressSanitizer is **2x**.
2626
How to build
2727
============
2828

29-
Build LLVM/Clang with `CMake <https://llvm.org/docs/CMake.html>` and enable
29+
Build LLVM/Clang with `CMake <https://llvm.org/docs/CMake.html>`_ and enable
3030
the ``compiler-rt`` runtime. An example CMake configuration that will allow
3131
for the use/testing of AddressSanitizer:
3232

clang/docs/RealtimeSanitizer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The runtime slowdown introduced by RealtimeSanitizer is negligible.
2121
How to build
2222
============
2323

24-
Build LLVM/Clang with `CMake <https://llvm.org/docs/CMake.html>` and enable the
24+
Build LLVM/Clang with `CMake <https://llvm.org/docs/CMake.html>`_ and enable the
2525
``compiler-rt`` runtime. An example CMake configuration that will allow for the
2626
use/testing of RealtimeSanitizer:
2727

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ Modified Compiler Flags
349349
to utilize these vector libraries. The behavior for all other vector function
350350
libraries remains unchanged.
351351

352+
- The ``-Wnontrivial-memaccess`` warning has been updated to also warn about
353+
passing non-trivially-copyable destrination parameter to ``memcpy``,
354+
``memset`` and similar functions for which it is a documented undefined
355+
behavior.
356+
352357
Removed Compiler Flags
353358
-------------------------
354359

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ struct UncheckedOptionalAccessModelOptions {
3737
/// can't identify when their results are used safely (across calls),
3838
/// resulting in false positives in all such cases. Note: this option does not
3939
/// cover access through `operator[]`.
40+
/// FIXME: we currently cache and equate the result of const accessors
41+
/// returning pointers, so cover the case of operator-> followed by
42+
/// operator->, which covers the common case of smart pointers. We also cover
43+
/// some limited cases of returning references (if return type is an optional
44+
/// type), so cover some cases of operator* followed by operator*. We don't
45+
/// cover mixing operator-> and operator*. Once we are confident in this const
46+
/// accessor caching, we shouldn't need the IgnoreSmartPointerDereference
47+
/// option anymore.
4048
bool IgnoreSmartPointerDereference = false;
4149
};
4250

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4871,6 +4871,12 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
48714871
let Prototype = "void(...)";
48724872
}
48734873

4874+
def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
4875+
let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
4876+
let Attributes = [NoThrow, Const];
4877+
let Prototype = "void(...)";
4878+
}
4879+
48744880
// Builtins for XRay.
48754881
def XRayCustomEvent : Builtin {
48764882
let Spellings = ["__xray_customevent"];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,10 @@ def warn_cstruct_memaccess : Warning<
795795
"%1 call is a pointer to record %2 that is not trivial to "
796796
"%select{primitive-default-initialize|primitive-copy}3">,
797797
InGroup<NonTrivialMemaccess>;
798+
def warn_cxxstruct_memaccess : Warning<
799+
"first argument in call to "
800+
"%0 is a pointer to non-trivially copyable type %1">,
801+
InGroup<NonTrivialMemaccess>;
798802
def note_nontrivial_field : Note<
799803
"field is non-trivial to %select{copy|default-initialize}0">;
800804
def err_non_trivial_c_union_in_invalid_context : Error<

clang/include/clang/Basic/Module.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class alignas(8) Module {
227227

228228
/// A mapping from the submodule name to the index into the
229229
/// \c SubModules vector at which that submodule resides.
230-
llvm::StringMap<unsigned> SubModuleIndex;
230+
mutable llvm::StringMap<unsigned> SubModuleIndex;
231231

232232
/// The AST file if this is a top-level module which has a
233233
/// corresponding serialized AST file, or null otherwise.
@@ -612,7 +612,6 @@ class alignas(8) Module {
612612
void setParent(Module *M) {
613613
assert(!Parent);
614614
Parent = M;
615-
Parent->SubModuleIndex[Name] = Parent->SubModules.size();
616615
Parent->SubModules.push_back(this);
617616
}
618617

clang/include/clang/Lex/ModuleMap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,17 @@ class ModuleMap {
546546
std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
547547
bool IsFramework,
548548
bool IsExplicit);
549+
/// Call \c ModuleMap::findOrCreateModule and throw away the information
550+
/// whether the module was found or created.
551+
Module *findOrCreateModuleFirst(StringRef Name, Module *Parent,
552+
bool IsFramework, bool IsExplicit) {
553+
return findOrCreateModule(Name, Parent, IsFramework, IsExplicit).first;
554+
}
555+
/// Create new submodule, assuming it does not exist. This function can only
556+
/// be called when it is guaranteed that this submodule does not exist yet.
557+
/// The parameters have same semantics as \c ModuleMap::findOrCreateModule.
558+
Module *createModule(StringRef Name, Module *Parent, bool IsFramework,
559+
bool IsExplicit);
549560

550561
/// Create a global module fragment for a C++ module unit.
551562
///

clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ auto isZeroParamConstMemberCall() {
338338
callee(cxxMethodDecl(parameterCountIs(0), isConst())));
339339
}
340340

341+
auto isZeroParamConstMemberOperatorCall() {
342+
return cxxOperatorCallExpr(
343+
callee(cxxMethodDecl(parameterCountIs(0), isConst())));
344+
}
345+
341346
auto isNonConstMemberCall() {
342347
return cxxMemberCallExpr(callee(cxxMethodDecl(unless(isConst()))));
343348
}
@@ -572,9 +577,10 @@ void handleConstMemberCall(const CallExpr *CE,
572577
return;
573578
}
574579

575-
// Cache if the const method returns a boolean type.
580+
// Cache if the const method returns a boolean or pointer type.
576581
// We may decide to cache other return types in the future.
577-
if (RecordLoc != nullptr && CE->getType()->isBooleanType()) {
582+
if (RecordLoc != nullptr &&
583+
(CE->getType()->isBooleanType() || CE->getType()->isPointerType())) {
578584
Value *Val = State.Lattice.getOrCreateConstMethodReturnValue(*RecordLoc, CE,
579585
State.Env);
580586
if (Val == nullptr)
@@ -597,6 +603,14 @@ void transferValue_ConstMemberCall(const CXXMemberCallExpr *MCE,
597603
MCE, dataflow::getImplicitObjectLocation(*MCE, State.Env), Result, State);
598604
}
599605

606+
void transferValue_ConstMemberOperatorCall(
607+
const CXXOperatorCallExpr *OCE, const MatchFinder::MatchResult &Result,
608+
LatticeTransferState &State) {
609+
auto *RecordLoc = cast_or_null<dataflow::RecordStorageLocation>(
610+
State.Env.getStorageLocation(*OCE->getArg(0)));
611+
handleConstMemberCall(OCE, RecordLoc, Result, State);
612+
}
613+
600614
void handleNonConstMemberCall(const CallExpr *CE,
601615
dataflow::RecordStorageLocation *RecordLoc,
602616
const MatchFinder::MatchResult &Result,
@@ -1020,6 +1034,8 @@ auto buildTransferMatchSwitch() {
10201034
// const accessor calls
10211035
.CaseOfCFGStmt<CXXMemberCallExpr>(isZeroParamConstMemberCall(),
10221036
transferValue_ConstMemberCall)
1037+
.CaseOfCFGStmt<CXXOperatorCallExpr>(isZeroParamConstMemberOperatorCall(),
1038+
transferValue_ConstMemberOperatorCall)
10231039
// non-const member calls that may modify the state of an object.
10241040
.CaseOfCFGStmt<CXXMemberCallExpr>(isNonConstMemberCall(),
10251041
transferValue_NonConstMemberCall)

clang/lib/Basic/Module.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ Module::Module(ModuleConstructorTag, StringRef Name,
5454
NoUndeclaredIncludes = Parent->NoUndeclaredIncludes;
5555
ModuleMapIsPrivate = Parent->ModuleMapIsPrivate;
5656

57-
Parent->SubModuleIndex[Name] = Parent->SubModules.size();
5857
Parent->SubModules.push_back(this);
5958
}
6059
}
@@ -351,11 +350,14 @@ void Module::markUnavailable(bool Unimportable) {
351350
}
352351

353352
Module *Module::findSubmodule(StringRef Name) const {
354-
llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
355-
if (Pos == SubModuleIndex.end())
356-
return nullptr;
353+
// Add new submodules into the index.
354+
for (unsigned I = SubModuleIndex.size(), E = SubModules.size(); I != E; ++I)
355+
SubModuleIndex[SubModules[I]->Name] = I;
357356

358-
return SubModules[Pos->getValue()];
357+
if (auto It = SubModuleIndex.find(Name); It != SubModuleIndex.end())
358+
return SubModules[It->second];
359+
360+
return nullptr;
359361
}
360362

361363
Module *Module::getGlobalModuleFragment() const {

clang/lib/Basic/Targets/X86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ bool X86TargetInfo::validateAsmConstraint(
14651465
}
14661466
case 'f': // Any x87 floating point stack register.
14671467
// Constraint 'f' cannot be used for output operands.
1468-
if (Info.ConstraintStr[0] == '=')
1468+
if (Info.ConstraintStr[0] == '=' || Info.ConstraintStr[0] == '+')
14691469
return false;
14701470
Info.setAllowsRegister();
14711471
return true;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "CGObjCRuntime.h"
1818
#include "CGOpenCLRuntime.h"
1919
#include "CGRecordLayout.h"
20+
#include "CGValue.h"
2021
#include "CodeGenFunction.h"
2122
#include "CodeGenModule.h"
2223
#include "ConstantEmitter.h"
@@ -25,8 +26,10 @@
2526
#include "clang/AST/ASTContext.h"
2627
#include "clang/AST/Attr.h"
2728
#include "clang/AST/Decl.h"
29+
#include "clang/AST/Expr.h"
2830
#include "clang/AST/OSLog.h"
2931
#include "clang/AST/OperationKinds.h"
32+
#include "clang/AST/Type.h"
3033
#include "clang/Basic/TargetBuiltins.h"
3134
#include "clang/Basic/TargetInfo.h"
3235
#include "clang/Basic/TargetOptions.h"
@@ -67,6 +70,7 @@
6770
#include "llvm/TargetParser/X86TargetParser.h"
6871
#include <optional>
6972
#include <sstream>
73+
#include <utility>
7074

7175
using namespace clang;
7276
using namespace CodeGen;
@@ -95,6 +99,76 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size,
9599
I->addAnnotationMetadata("auto-init");
96100
}
97101

102+
static Value *handleHlslSplitdouble(const CallExpr *E, CodeGenFunction *CGF) {
103+
Value *Op0 = CGF->EmitScalarExpr(E->getArg(0));
104+
const auto *OutArg1 = dyn_cast<HLSLOutArgExpr>(E->getArg(1));
105+
const auto *OutArg2 = dyn_cast<HLSLOutArgExpr>(E->getArg(2));
106+
107+
CallArgList Args;
108+
LValue Op1TmpLValue =
109+
CGF->EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType());
110+
LValue Op2TmpLValue =
111+
CGF->EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType());
112+
113+
if (CGF->getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee())
114+
Args.reverseWritebacks();
115+
116+
Value *LowBits = nullptr;
117+
Value *HighBits = nullptr;
118+
119+
if (CGF->CGM.getTarget().getTriple().isDXIL()) {
120+
121+
llvm::Type *RetElementTy = CGF->Int32Ty;
122+
if (auto *Op0VecTy = E->getArg(0)->getType()->getAs<clang::VectorType>())
123+
RetElementTy = llvm::VectorType::get(
124+
CGF->Int32Ty, ElementCount::getFixed(Op0VecTy->getNumElements()));
125+
auto *RetTy = llvm::StructType::get(RetElementTy, RetElementTy);
126+
127+
CallInst *CI = CGF->Builder.CreateIntrinsic(
128+
RetTy, Intrinsic::dx_splitdouble, {Op0}, nullptr, "hlsl.splitdouble");
129+
130+
LowBits = CGF->Builder.CreateExtractValue(CI, 0);
131+
HighBits = CGF->Builder.CreateExtractValue(CI, 1);
132+
133+
} else {
134+
// For Non DXIL targets we generate the instructions.
135+
136+
if (!Op0->getType()->isVectorTy()) {
137+
FixedVectorType *DestTy = FixedVectorType::get(CGF->Int32Ty, 2);
138+
Value *Bitcast = CGF->Builder.CreateBitCast(Op0, DestTy);
139+
140+
LowBits = CGF->Builder.CreateExtractElement(Bitcast, (uint64_t)0);
141+
HighBits = CGF->Builder.CreateExtractElement(Bitcast, 1);
142+
} else {
143+
int NumElements = 1;
144+
if (const auto *VecTy =
145+
E->getArg(0)->getType()->getAs<clang::VectorType>())
146+
NumElements = VecTy->getNumElements();
147+
148+
FixedVectorType *Uint32VecTy =
149+
FixedVectorType::get(CGF->Int32Ty, NumElements * 2);
150+
Value *Uint32Vec = CGF->Builder.CreateBitCast(Op0, Uint32VecTy);
151+
if (NumElements == 1) {
152+
LowBits = CGF->Builder.CreateExtractElement(Uint32Vec, (uint64_t)0);
153+
HighBits = CGF->Builder.CreateExtractElement(Uint32Vec, 1);
154+
} else {
155+
SmallVector<int> EvenMask, OddMask;
156+
for (int I = 0, E = NumElements; I != E; ++I) {
157+
EvenMask.push_back(I * 2);
158+
OddMask.push_back(I * 2 + 1);
159+
}
160+
LowBits = CGF->Builder.CreateShuffleVector(Uint32Vec, EvenMask);
161+
HighBits = CGF->Builder.CreateShuffleVector(Uint32Vec, OddMask);
162+
}
163+
}
164+
}
165+
CGF->Builder.CreateStore(LowBits, Op1TmpLValue.getAddress());
166+
auto *LastInst =
167+
CGF->Builder.CreateStore(HighBits, Op2TmpLValue.getAddress());
168+
CGF->EmitWritebacks(Args);
169+
return LastInst;
170+
}
171+
98172
/// getBuiltinLibFunction - Given a builtin id for a function like
99173
/// "__builtin_fabsf", return a Function* for "fabsf".
100174
llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
@@ -18956,6 +19030,14 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1895619030
CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef<Value *>{Op0},
1895719031
nullptr, "hlsl.radians");
1895819032
}
19033+
case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
19034+
19035+
assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
19036+
E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() &&
19037+
E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) &&
19038+
"asuint operands types mismatch");
19039+
return handleHlslSplitdouble(E, this);
19040+
}
1895919041
}
1896019042
return nullptr;
1896119043
}

clang/lib/CodeGen/CGCall.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "llvm/IR/IntrinsicInst.h"
4141
#include "llvm/IR/Intrinsics.h"
4242
#include "llvm/IR/Type.h"
43+
#include "llvm/Support/Path.h"
4344
#include "llvm/Transforms/Utils/Local.h"
4445
#include <optional>
4546
using namespace clang;
@@ -4257,12 +4258,6 @@ static void emitWriteback(CodeGenFunction &CGF,
42574258
CGF.EmitBlock(contBB);
42584259
}
42594260

4260-
static void emitWritebacks(CodeGenFunction &CGF,
4261-
const CallArgList &args) {
4262-
for (const auto &I : args.writebacks())
4263-
emitWriteback(CGF, I);
4264-
}
4265-
42664261
static void deactivateArgCleanupsBeforeCall(CodeGenFunction &CGF,
42674262
const CallArgList &CallArgs) {
42684263
ArrayRef<CallArgList::CallArgCleanup> Cleanups =
@@ -4731,6 +4726,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address Addr) const {
47314726
IsUsed = true;
47324727
}
47334728

4729+
void CodeGenFunction::EmitWritebacks(const CallArgList &args) {
4730+
for (const auto &I : args.writebacks())
4731+
emitWriteback(*this, I);
4732+
}
4733+
47344734
void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
47354735
QualType type) {
47364736
DisableDebugLocationUpdates Dis(*this, E);
@@ -5954,7 +5954,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
59545954
// Emit any call-associated writebacks immediately. Arguably this
59555955
// should happen after any return-value munging.
59565956
if (CallArgs.hasWritebacks())
5957-
emitWritebacks(*this, CallArgs);
5957+
EmitWritebacks(CallArgs);
59585958

59595959
// The stack cleanup for inalloca arguments has to run out of the normal
59605960
// lexical order, so deactivate it and run it manually here.

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5460,9 +5460,8 @@ LValue CodeGenFunction::EmitOpaqueValueLValue(const OpaqueValueExpr *e) {
54605460
return getOrCreateOpaqueLValueMapping(e);
54615461
}
54625462

5463-
void CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
5464-
CallArgList &Args, QualType Ty) {
5465-
5463+
std::pair<LValue, LValue>
5464+
CodeGenFunction::EmitHLSLOutArgLValues(const HLSLOutArgExpr *E, QualType Ty) {
54665465
// Emitting the casted temporary through an opaque value.
54675466
LValue BaseLV = EmitLValue(E->getArgLValue());
54685467
OpaqueValueMappingData::bind(*this, E->getOpaqueArgLValue(), BaseLV);
@@ -5476,6 +5475,13 @@ void CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
54765475
TempLV);
54775476

54785477
OpaqueValueMappingData::bind(*this, E->getCastedTemporary(), TempLV);
5478+
return std::make_pair(BaseLV, TempLV);
5479+
}
5480+
5481+
LValue CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
5482+
CallArgList &Args, QualType Ty) {
5483+
5484+
auto [BaseLV, TempLV] = EmitHLSLOutArgLValues(E, Ty);
54795485

54805486
llvm::Value *Addr = TempLV.getAddress().getBasePointer();
54815487
llvm::Type *ElTy = ConvertTypeForMem(TempLV.getType());
@@ -5488,6 +5494,7 @@ void CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
54885494
Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast(),
54895495
LifetimeSize);
54905496
Args.add(RValue::get(TmpAddr, *this), Ty);
5497+
return TempLV;
54915498
}
54925499

54935500
LValue

0 commit comments

Comments
 (0)