Skip to content

Commit 4ef7636

Browse files
authored
merge main into amd-staging (llvm#4042)
2 parents adfcdd5 + 045d0d9 commit 4ef7636

File tree

70 files changed

+1346
-265
lines changed

Some content is hidden

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

70 files changed

+1346
-265
lines changed

.github/workflows/build-ci-container-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6262
steps:
6363
- name: Download container
64-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
64+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
6565
with:
6666
name: container
6767
- name: Push Container

.github/workflows/build-ci-container.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8989
steps:
9090
- name: Download container
91-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
91+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
9292

9393
- name: Push Container
9494
run: |

.github/workflows/build-metrics-container.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6767
steps:
6868
- name: Download Container
69-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
69+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
7070
with:
7171
name: container
7272
- name: Push Container

.github/workflows/libclang-abi-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ jobs:
144144
- abi-dump
145145
steps:
146146
- name: Download baseline
147-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # 4.1.8
147+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
148148
with:
149149
name: build-baseline
150150
path: build-baseline
151151
- name: Download latest
152-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # 4.1.8
152+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
153153
with:
154154
name: build-latest
155155
path: build-latest

.github/workflows/llvm-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ jobs:
148148
- abi-dump
149149
steps:
150150
- name: Download baseline
151-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # 4.1.8
151+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
152152
with:
153153
name: build-baseline
154154
path: build-baseline
155155
- name: Download latest
156-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # 4.1.8
156+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
157157
with:
158158
name: build-latest
159159
path: build-latest
160160
- name: Download symbol list
161-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # 4.1.8
161+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
162162
with:
163163
name: symbol-list
164164
path: symbol-list

.github/workflows/release-binaries-setup-stage/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ runs:
4444
- name: Download Previous Stage Artifact
4545
if: ${{ inputs.previous-artifact }}
4646
id: download
47-
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
47+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
4848
with:
4949
pattern: ${{ runner.os }}-${{ runner.arch }}-${{ inputs.previous-artifact }}-*
5050
merge-multiple: true

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ jobs:
294294
sparse-checkout-cone-mode: false
295295

296296
- name: 'Download artifact'
297-
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
297+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
298298
with:
299299
pattern: '*-release-binary'
300300
merge-multiple: true

clang/lib/Analysis/LifetimeSafety.cpp

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,25 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
478478
}
479479
}
480480

481+
void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
482+
if (isGslPointerType(CCE->getType())) {
483+
handleGSLPointerConstruction(CCE);
484+
return;
485+
}
486+
}
487+
488+
void VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
489+
// Specifically for conversion operators,
490+
// like `std::string_view p = std::string{};`
491+
if (isGslPointerType(MCE->getType()) &&
492+
isa<CXXConversionDecl>(MCE->getCalleeDecl())) {
493+
// The argument is the implicit object itself.
494+
handleFunctionCall(MCE, MCE->getMethodDecl(),
495+
{MCE->getImplicitObjectArgument()});
496+
}
497+
// FIXME: A more general VisitCallExpr could also be used here.
498+
}
499+
481500
void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *N) {
482501
/// TODO: Handle nullptr expr as a special 'null' loan. Uninitialized
483502
/// pointers can use the same type of loan.
@@ -530,8 +549,27 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
530549
void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *FCE) {
531550
// Check if this is a test point marker. If so, we are done with this
532551
// expression.
533-
if (VisitTestPoint(FCE))
552+
if (handleTestPoint(FCE))
534553
return;
554+
if (isGslPointerType(FCE->getType()))
555+
addAssignOriginFact(*FCE, *FCE->getSubExpr());
556+
}
557+
558+
void VisitInitListExpr(const InitListExpr *ILE) {
559+
if (!hasOrigin(ILE))
560+
return;
561+
// For list initialization with a single element, like `View{...}`, the
562+
// origin of the list itself is the origin of its single element.
563+
if (ILE->getNumInits() == 1)
564+
addAssignOriginFact(*ILE, *ILE->getInit(0));
565+
}
566+
567+
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *MTE) {
568+
if (!hasOrigin(MTE))
569+
return;
570+
// A temporary object's origin is the same as the origin of the
571+
// expression that initializes it.
572+
addAssignOriginFact(*MTE, *MTE->getSubExpr());
535573
}
536574

537575
void handleDestructor(const CFGAutomaticObjDtor &DtorOpt) {
@@ -557,10 +595,21 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
557595
}
558596

559597
private:
560-
static bool isPointerType(QualType QT) {
561-
return QT->isPointerOrReferenceType();
598+
static bool isGslPointerType(QualType QT) {
599+
if (const auto *RD = QT->getAsCXXRecordDecl()) {
600+
// We need to check the template definition for specializations.
601+
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
602+
return CTSD->getSpecializedTemplate()
603+
->getTemplatedDecl()
604+
->hasAttr<PointerAttr>();
605+
return RD->hasAttr<PointerAttr>();
606+
}
607+
return false;
562608
}
563609

610+
static bool isPointerType(QualType QT) {
611+
return QT->isPointerOrReferenceType() || isGslPointerType(QT);
612+
}
564613
// Check if a type has an origin.
565614
static bool hasOrigin(const Expr *E) {
566615
return E->isGLValue() || isPointerType(E->getType());
@@ -570,6 +619,41 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
570619
return isPointerType(VD->getType());
571620
}
572621

622+
void handleGSLPointerConstruction(const CXXConstructExpr *CCE) {
623+
assert(isGslPointerType(CCE->getType()));
624+
if (CCE->getNumArgs() != 1)
625+
return;
626+
if (hasOrigin(CCE->getArg(0)))
627+
addAssignOriginFact(*CCE, *CCE->getArg(0));
628+
else
629+
// This could be a new borrow.
630+
handleFunctionCall(CCE, CCE->getConstructor(),
631+
{CCE->getArgs(), CCE->getNumArgs()});
632+
}
633+
634+
/// Checks if a call-like expression creates a borrow by passing a value to a
635+
/// reference parameter, creating an IssueFact if it does.
636+
void handleFunctionCall(const Expr *Call, const FunctionDecl *FD,
637+
ArrayRef<const Expr *> Args) {
638+
if (!FD)
639+
return;
640+
// TODO: Handle more than one arguments.
641+
for (unsigned I = 0; I <= 0 /*Args.size()*/; ++I) {
642+
const Expr *ArgExpr = Args[I];
643+
644+
// Propagate origins for CXX this.
645+
if (FD->isCXXClassMember() && I == 0) {
646+
addAssignOriginFact(*Call, *ArgExpr);
647+
continue;
648+
}
649+
// The parameter is a pointer, reference, or gsl::Pointer.
650+
// This is a borrow. We propagate the origin from the argument expression
651+
// at the call site to the parameter declaration in the callee.
652+
if (hasOrigin(ArgExpr))
653+
addAssignOriginFact(*Call, *ArgExpr);
654+
}
655+
}
656+
573657
/// Creates a loan for the storage path of a given declaration reference.
574658
/// This function should be called whenever a DeclRefExpr represents a borrow.
575659
/// \param DRE The declaration reference expression that initiates the borrow.
@@ -593,7 +677,7 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
593677

594678
/// Checks if the expression is a `void("__lifetime_test_point_...")` cast.
595679
/// If so, creates a `TestPointFact` and returns true.
596-
bool VisitTestPoint(const CXXFunctionalCastExpr *FCE) {
680+
bool handleTestPoint(const CXXFunctionalCastExpr *FCE) {
597681
if (!FCE->getType()->isVoidType())
598682
return false;
599683

@@ -641,6 +725,8 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
641725
}
642726

643727
void markUseAsWrite(const DeclRefExpr *DRE) {
728+
if (!isPointerType(DRE->getType()))
729+
return;
644730
assert(UseFacts.contains(DRE));
645731
UseFacts[DRE]->markAsWritten();
646732
}

clang/lib/Basic/Targets/X86.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,29 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
999999
Builder.defineMacro("_GNU_SOURCE");
10001000
}
10011001

1002+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
1003+
switch (CC) {
1004+
case CC_X86StdCall:
1005+
case CC_X86ThisCall:
1006+
case CC_X86FastCall:
1007+
return CCCR_Ignore;
1008+
case CC_C:
1009+
case CC_X86VectorCall:
1010+
case CC_IntelOclBicc:
1011+
case CC_PreserveMost:
1012+
case CC_PreserveAll:
1013+
case CC_PreserveNone:
1014+
case CC_X86_64SysV:
1015+
case CC_Swift:
1016+
case CC_SwiftAsync:
1017+
case CC_X86RegCall:
1018+
case CC_DeviceKernel:
1019+
return CCCR_OK;
1020+
default:
1021+
return CCCR_Warning;
1022+
}
1023+
}
1024+
10021025
BuiltinVaListKind getBuiltinVaListKind() const override {
10031026
return TargetInfo::CharPtrBuiltinVaList;
10041027
}

clang/test/CodeGen/X86/cygwin-varargs.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)