Skip to content

Commit c9c38c8

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-compute-iv-end-values
2 parents c6cc339 + 4e828f8 commit c9c38c8

File tree

653 files changed

+23462
-5636
lines changed

Some content is hidden

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

653 files changed

+23462
-5636
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ Improvements to Clang's diagnostics
614614

615615
- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073).
616616

617+
- Fix false positives when `[[gsl::Owner/Pointer]]` and `[[clang::lifetimebound]]` are used together.
618+
617619
- Improved diagnostic message for ``__builtin_bit_cast`` size mismatch (#GH115870).
618620

619621
- Clang now omits shadow warnings for enum constants in separate class scopes (#GH62588).

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ inline bool isOpenACCCombinedDirectiveKind(OpenACCDirectiveKind K) {
158158
K == OpenACCDirectiveKind::KernelsLoop;
159159
}
160160

161+
// Tests 'K' to see if it is 'data', 'host_data', 'enter data', or 'exit data'.
162+
inline bool isOpenACCDataDirectiveKind(OpenACCDirectiveKind K) {
163+
return K == OpenACCDirectiveKind::Data ||
164+
K == OpenACCDirectiveKind::EnterData ||
165+
K == OpenACCDirectiveKind::ExitData ||
166+
K == OpenACCDirectiveKind::HostData;
167+
}
168+
161169
enum class OpenACCAtomicKind : uint8_t {
162170
Read,
163171
Write,

clang/lib/Basic/SourceManager.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ bool needConversion(StringRef Filename) {
592592
#ifdef __MVS__
593593
llvm::ErrorOr<bool> NeedConversion =
594594
llvm::needzOSConversion(Filename.str().c_str());
595-
assert(NeedConversion && "Filename was not found");
596-
return *NeedConversion;
595+
return NeedConversion && *NeedConversion;
597596
#else
598597
return false;
599598
#endif

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3773,7 +3773,8 @@ static void RenderSCPOptions(const ToolChain &TC, const ArgList &Args,
37733773
ArgStringList &CmdArgs) {
37743774
const llvm::Triple &EffectiveTriple = TC.getEffectiveTriple();
37753775

3776-
if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux())
3776+
if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux() &&
3777+
!EffectiveTriple.isOSFuchsia())
37773778
return;
37783779

37793780
if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 93 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ static bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee) {
367367
if (Callee->getReturnType()->isReferenceType()) {
368368
if (!Callee->getIdentifier()) {
369369
auto OO = Callee->getOverloadedOperator();
370+
if (!Callee->getParent()->hasAttr<OwnerAttr>())
371+
return false;
370372
return OO == OverloadedOperatorKind::OO_Subscript ||
371373
OO == OverloadedOperatorKind::OO_Star;
372374
}
@@ -1152,6 +1154,86 @@ static bool pathOnlyHandlesGslPointer(const IndirectLocalPath &Path) {
11521154
}
11531155
return false;
11541156
}
1157+
// Result of analyzing the Path for GSLPointer.
1158+
enum AnalysisResult {
1159+
// Path does not correspond to a GSLPointer.
1160+
NotGSLPointer,
1161+
1162+
// A relevant case was identified.
1163+
Report,
1164+
// Stop the entire traversal.
1165+
Abandon,
1166+
// Skip this step and continue traversing inner AST nodes.
1167+
Skip,
1168+
};
1169+
// Analyze cases where a GSLPointer is initialized or assigned from a
1170+
// temporary owner object.
1171+
static AnalysisResult analyzePathForGSLPointer(const IndirectLocalPath &Path,
1172+
Local L) {
1173+
if (!pathOnlyHandlesGslPointer(Path))
1174+
return NotGSLPointer;
1175+
1176+
// At this point, Path represents a series of operations involving a
1177+
// GSLPointer, either in the process of initialization or assignment.
1178+
1179+
// Note: A LifetimeBoundCall can appear interleaved in this sequence.
1180+
// For example:
1181+
// const std::string& Ref(const std::string& a [[clang::lifetimebound]]);
1182+
// string_view abc = Ref(std::string());
1183+
// The "Path" is [GSLPointerInit, LifetimeboundCall], where "L" is the
1184+
// temporary "std::string()" object. We need to check the return type of the
1185+
// function with the lifetimebound attribute.
1186+
if (Path.back().Kind == IndirectLocalPathEntry::LifetimeBoundCall) {
1187+
// The lifetimebound applies to the implicit object parameter of a method.
1188+
const FunctionDecl *FD =
1189+
llvm::dyn_cast_or_null<FunctionDecl>(Path.back().D);
1190+
// The lifetimebound applies to a function parameter.
1191+
if (const auto *PD = llvm::dyn_cast<ParmVarDecl>(Path.back().D))
1192+
FD = llvm::dyn_cast<FunctionDecl>(PD->getDeclContext());
1193+
1194+
if (isa_and_present<CXXConstructorDecl>(FD)) {
1195+
// Constructor case: the parameter is annotated with lifetimebound
1196+
// e.g., GSLPointer(const S& s [[clang::lifetimebound]])
1197+
// We still respect this case even the type S is not an owner.
1198+
return Report;
1199+
}
1200+
// Check the return type, e.g.
1201+
// const GSLOwner& func(const Foo& foo [[clang::lifetimebound]])
1202+
// GSLPointer func(const Foo& foo [[clang::lifetimebound]])
1203+
if (FD &&
1204+
((FD->getReturnType()->isReferenceType() &&
1205+
isRecordWithAttr<OwnerAttr>(FD->getReturnType()->getPointeeType())) ||
1206+
isPointerLikeType(FD->getReturnType())))
1207+
return Report;
1208+
1209+
return Abandon;
1210+
}
1211+
1212+
if (isa<DeclRefExpr>(L)) {
1213+
// We do not want to follow the references when returning a pointer
1214+
// originating from a local owner to avoid the following false positive:
1215+
// int &p = *localUniquePtr;
1216+
// someContainer.add(std::move(localUniquePtr));
1217+
// return p;
1218+
if (!pathContainsInit(Path) && isRecordWithAttr<OwnerAttr>(L->getType()))
1219+
return Report;
1220+
return Abandon;
1221+
}
1222+
1223+
// The GSLPointer is from a temporary object.
1224+
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L);
1225+
1226+
bool IsGslPtrValueFromGslTempOwner =
1227+
MTE && !MTE->getExtendingDecl() &&
1228+
isRecordWithAttr<OwnerAttr>(MTE->getType());
1229+
// Skipping a chain of initializing gsl::Pointer annotated objects.
1230+
// We are looking only for the final source to find out if it was
1231+
// a local or temporary owner or the address of a local
1232+
// variable/param.
1233+
if (!IsGslPtrValueFromGslTempOwner)
1234+
return Skip;
1235+
return Report;
1236+
}
11551237

11561238
static bool isAssignmentOperatorLifetimeBound(CXXMethodDecl *CMD) {
11571239
return CMD && isNormalAssignmentOperator(CMD) && CMD->param_size() == 1 &&
@@ -1189,27 +1271,17 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
11891271

11901272
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L);
11911273

1192-
bool IsGslPtrValueFromGslTempOwner = false;
1193-
if (pathOnlyHandlesGslPointer(Path)) {
1194-
if (isa<DeclRefExpr>(L)) {
1195-
// We do not want to follow the references when returning a pointer
1196-
// originating from a local owner to avoid the following false positive:
1197-
// int &p = *localUniquePtr;
1198-
// someContainer.add(std::move(localUniquePtr));
1199-
// return p;
1200-
if (pathContainsInit(Path) ||
1201-
!isRecordWithAttr<OwnerAttr>(L->getType()))
1202-
return false;
1203-
} else {
1204-
IsGslPtrValueFromGslTempOwner =
1205-
MTE && !MTE->getExtendingDecl() &&
1206-
isRecordWithAttr<OwnerAttr>(MTE->getType());
1207-
// Skipping a chain of initializing gsl::Pointer annotated objects.
1208-
// We are looking only for the final source to find out if it was
1209-
// a local or temporary owner or the address of a local variable/param.
1210-
if (!IsGslPtrValueFromGslTempOwner)
1211-
return true;
1212-
}
1274+
bool IsGslPtrValueFromGslTempOwner = true;
1275+
switch (analyzePathForGSLPointer(Path, L)) {
1276+
case Abandon:
1277+
return false;
1278+
case Skip:
1279+
return true;
1280+
case NotGSLPointer:
1281+
IsGslPtrValueFromGslTempOwner = false;
1282+
LLVM_FALLTHROUGH;
1283+
case Report:
1284+
break;
12131285
}
12141286

12151287
switch (LK) {

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,12 @@ bool checkAlreadyHasClauseOfKind(
435435
bool checkValidAfterDeviceType(
436436
SemaOpenACC &S, const OpenACCDeviceTypeClause &DeviceTypeClause,
437437
const SemaOpenACC::OpenACCParsedClause &NewClause) {
438-
// This is only a requirement on compute and loop constructs so far, so this
439-
// is fine otherwise.
438+
// This is only a requirement on compute, combined, data and loop constructs
439+
// so far, so this is fine otherwise.
440440
if (!isOpenACCComputeDirectiveKind(NewClause.getDirectiveKind()) &&
441441
!isOpenACCCombinedDirectiveKind(NewClause.getDirectiveKind()) &&
442-
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
442+
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
443+
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Data)
443444
return false;
444445

445446
// OpenACC3.3: Section 2.4: Clauses that precede any device_type clause are
@@ -504,6 +505,16 @@ bool checkValidAfterDeviceType(
504505
default:
505506
break;
506507
}
508+
} else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Data) {
509+
// OpenACC3.3 section 2.6.5: Only the async and wait clauses may follow a
510+
// device_type clause.
511+
switch (NewClause.getClauseKind()) {
512+
case OpenACCClauseKind::Async:
513+
case OpenACCClauseKind::Wait:
514+
return false;
515+
default:
516+
break;
517+
}
507518
}
508519
S.Diag(NewClause.getBeginLoc(), diag::err_acc_clause_after_device_type)
509520
<< NewClause.getClauseKind() << DeviceTypeClause.getClauseKind()
@@ -630,16 +641,20 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitTileClause(
630641

631642
OpenACCClause *SemaOpenACCClauseVisitor::VisitIfClause(
632643
SemaOpenACC::OpenACCParsedClause &Clause) {
633-
// Restrictions only properly implemented on 'compute'/'combined' constructs,
634-
// and 'compute'/'combined' constructs are the only construct that can do
635-
// anything with this yet, so skip/treat as unimplemented in this case.
644+
// Restrictions only properly implemented on 'compute'/'combined'/'data'
645+
// constructs, and 'compute'/'combined'/'data' constructs are the only
646+
// constructs that can do anything with this yet, so skip/treat as
647+
// unimplemented in this case.
636648
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
637-
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
649+
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()) &&
650+
!isOpenACCDataDirectiveKind(Clause.getDirectiveKind()))
638651
return isNotImplemented();
639652

640653
// There is no prose in the standard that says duplicates aren't allowed,
641654
// but this diagnostic is present in other compilers, as well as makes
642-
// sense.
655+
// sense. Prose DOES exist for 'data' and 'host_data', 'enter data' and 'exit
656+
// data' both don't, but other implmementations do this. OpenACC issue 519
657+
// filed for the latter two.
643658
if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
644659
return nullptr;
645660

@@ -861,11 +876,13 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorLengthClause(
861876

862877
OpenACCClause *SemaOpenACCClauseVisitor::VisitAsyncClause(
863878
SemaOpenACC::OpenACCParsedClause &Clause) {
864-
// Restrictions only properly implemented on 'compute'/'combined' constructs,
865-
// and 'compute'/'combined' constructs are the only construct that can do
866-
// anything with this yet, so skip/treat as unimplemented in this case.
879+
// Restrictions only properly implemented on 'compute'/'combined'/'data'
880+
// constructs, and 'compute'/'combined'/'data' constructs are the only
881+
// construct that can do anything with this yet, so skip/treat as
882+
// unimplemented in this case.
867883
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
868-
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
884+
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()) &&
885+
!isOpenACCDataDirectiveKind(Clause.getDirectiveKind()))
869886
return isNotImplemented();
870887

871888
// There is no prose in the standard that says duplicates aren't allowed,
@@ -1067,12 +1084,13 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause(
10671084

10681085
OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
10691086
SemaOpenACC::OpenACCParsedClause &Clause) {
1070-
// Restrictions only properly implemented on 'compute', 'combined', and
1071-
// 'loop' constructs, and 'compute'/'combined'/'loop' constructs are the only
1072-
// construct that can do anything with this yet, so skip/treat as
1087+
// Restrictions only properly implemented on 'compute', 'combined', 'data' and
1088+
// 'loop' constructs, and 'compute'/'combined'/'data'/'loop' constructs are
1089+
// the only construct that can do anything with this yet, so skip/treat as
10731090
// unimplemented in this case.
10741091
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
10751092
Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
1093+
Clause.getDirectiveKind() != OpenACCDirectiveKind::Data &&
10761094
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
10771095
return isNotImplemented();
10781096

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool tryToFindPtrOrigin(
3333
E = tempExpr->getSubExpr();
3434
continue;
3535
}
36-
if (auto *tempExpr = dyn_cast<CXXTemporaryObjectExpr>(E)) {
36+
if (auto *tempExpr = dyn_cast<CXXConstructExpr>(E)) {
3737
if (auto *C = tempExpr->getConstructor()) {
3838
if (auto *Class = C->getParent(); Class && isSafePtr(Class))
3939
return callback(E, true);

clang/test/AST/ast-print-openacc-data-construct.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ void foo() {
1010
// CHECK-NOT: default(none)
1111
#pragma acc data default(none)
1212
;
13+
14+
// CHECK: #pragma acc data device_type(int)
15+
#pragma acc data device_type(int)
16+
;
17+
1318
// CHECK: #pragma acc enter data
1419
// CHECK-NOT: copyin(Var)
1520
#pragma acc enter data copyin(Var)
@@ -22,4 +27,28 @@ void foo() {
2227
// CHECK-NOT: use_device(Var)
2328
#pragma acc host_data use_device(Var)
2429
;
30+
31+
int i;
32+
int array[5];
33+
34+
// CHECK: #pragma acc data if(i == array[1])
35+
#pragma acc data default(none) if(i == array[1])
36+
;
37+
// CHECK: #pragma acc enter data if(i == array[1])
38+
#pragma acc enter data copyin(Var) if(i == array[1])
39+
;
40+
// CHECK: #pragma acc exit data if(i == array[1])
41+
#pragma acc exit data copyout(Var) if(i == array[1])
42+
;
43+
// CHECK: #pragma acc host_data if(i == array[1])
44+
#pragma acc host_data use_device(Var) if(i == array[1])
45+
;
46+
47+
// CHECK: #pragma acc data async(i)
48+
#pragma acc data default(none) async(i)
49+
;
50+
// CHECK: #pragma acc enter data async(i)
51+
#pragma acc enter data copyin(i) async(i)
52+
// CHECK: #pragma acc exit data async
53+
#pragma acc exit data copyout(i) async
2554
}

clang/test/Analysis/Checkers/WebKit/call-args.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,15 @@ namespace call_with_explicit_temporary_obj {
364364
Ref { *provide() }->method();
365365
RefPtr { provide() }->method();
366366
}
367+
template <typename T>
368+
void bar() {
369+
Ref(*provide())->method();
370+
RefPtr(provide())->method();
371+
}
372+
void baz() {
373+
bar<int>();
374+
}
375+
}
376+
377+
namespace call_with_explicit_construct {
367378
}

clang/test/Driver/stack-clash-protection.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
// SCP-ll-win64-NOT: attributes {{.*}} "probe-stack"="inline-asm"
2323
// SCP-ll-win64: argument unused during compilation: '-fstack-clash-protection'
2424

25+
// RUN: %clang -target x86_64-unknown-fuchsia -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-FUCHSIA
26+
// RUN: %clang -target aarch64-unknown-fuchsia -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-FUCHSIA
27+
// RUN: %clang -target riscv64-unknown-fuchsia -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-FUCHSIA
28+
// SCP-FUCHSIA: "-fstack-clash-protection"
29+
2530
int foo(int c) {
2631
int r;
2732
__asm__("sub %0, %%rsp"

0 commit comments

Comments
 (0)