Skip to content

Commit 6f4c8c5

Browse files
authored
Merge branch 'main' into ravil/rocdl-conv-ops
2 parents bc5d4e0 + 39d0e41 commit 6f4c8c5

File tree

86 files changed

+4374
-403
lines changed

Some content is hidden

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

86 files changed

+4374
-403
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ Bug Fixes to C++ Support
437437
- Fix the result of `__builtin_is_implicit_lifetime` for types with a user-provided constructor. (#GH160610)
438438
- Correctly deduce return types in ``decltype`` expressions. (#GH160497) (#GH56652) (#GH116319) (#GH161196)
439439
- Fixed a crash in the pre-C++23 warning for attributes before a lambda declarator (#GH161070).
440+
- Fix a crash when attempting to deduce a deduction guide from a non deducible template template parameter. (#130604)
440441

441442
Bug Fixes to AST Handling
442443
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -419,22 +419,28 @@ class LocalVariableMap {
419419
// The expression for this variable, OR
420420
const Expr *Exp = nullptr;
421421

422-
// Reference to another VarDefinition
423-
unsigned Ref = 0;
422+
// Direct reference to another VarDefinition
423+
unsigned DirectRef = 0;
424+
425+
// Reference to underlying canonical non-reference VarDefinition.
426+
unsigned CanonicalRef = 0;
424427

425428
// The map with which Exp should be interpreted.
426429
Context Ctx;
427430

428431
bool isReference() const { return !Exp; }
429432

433+
void invalidateRef() { DirectRef = CanonicalRef = 0; }
434+
430435
private:
431436
// Create ordinary variable definition
432437
VarDefinition(const NamedDecl *D, const Expr *E, Context C)
433438
: Dec(D), Exp(E), Ctx(C) {}
434439

435440
// Create reference to previous definition
436-
VarDefinition(const NamedDecl *D, unsigned R, Context C)
437-
: Dec(D), Ref(R), Ctx(C) {}
441+
VarDefinition(const NamedDecl *D, unsigned DirectRef, unsigned CanonicalRef,
442+
Context C)
443+
: Dec(D), DirectRef(DirectRef), CanonicalRef(CanonicalRef), Ctx(C) {}
438444
};
439445

440446
private:
@@ -445,7 +451,7 @@ class LocalVariableMap {
445451
public:
446452
LocalVariableMap() {
447453
// index 0 is a placeholder for undefined variables (aka phi-nodes).
448-
VarDefinitions.push_back(VarDefinition(nullptr, 0u, getEmptyContext()));
454+
VarDefinitions.push_back(VarDefinition(nullptr, 0, 0, getEmptyContext()));
449455
}
450456

451457
/// Look up a definition, within the given context.
@@ -471,7 +477,7 @@ class LocalVariableMap {
471477
Ctx = VarDefinitions[i].Ctx;
472478
return VarDefinitions[i].Exp;
473479
}
474-
i = VarDefinitions[i].Ref;
480+
i = VarDefinitions[i].DirectRef;
475481
}
476482
return nullptr;
477483
}
@@ -508,7 +514,7 @@ class LocalVariableMap {
508514
void dump() {
509515
for (unsigned i = 1, e = VarDefinitions.size(); i < e; ++i) {
510516
const Expr *Exp = VarDefinitions[i].Exp;
511-
unsigned Ref = VarDefinitions[i].Ref;
517+
unsigned Ref = VarDefinitions[i].DirectRef;
512518

513519
dumpVarDefinitionName(i);
514520
llvm::errs() << " = ";
@@ -539,9 +545,9 @@ class LocalVariableMap {
539545
friend class VarMapBuilder;
540546

541547
// Resolve any definition ID down to its non-reference base ID.
542-
unsigned getCanonicalDefinitionID(unsigned ID) {
548+
unsigned getCanonicalDefinitionID(unsigned ID) const {
543549
while (ID > 0 && VarDefinitions[ID].isReference())
544-
ID = VarDefinitions[ID].Ref;
550+
ID = VarDefinitions[ID].CanonicalRef;
545551
return ID;
546552
}
547553

@@ -564,10 +570,11 @@ class LocalVariableMap {
564570
}
565571

566572
// Add a new reference to an existing definition.
567-
Context addReference(const NamedDecl *D, unsigned i, Context Ctx) {
573+
Context addReference(const NamedDecl *D, unsigned Ref, Context Ctx) {
568574
unsigned newID = VarDefinitions.size();
569575
Context NewCtx = ContextFactory.add(Ctx, D, newID);
570-
VarDefinitions.push_back(VarDefinition(D, i, Ctx));
576+
VarDefinitions.push_back(
577+
VarDefinition(D, Ref, getCanonicalDefinitionID(Ref), Ctx));
571578
return NewCtx;
572579
}
573580

@@ -769,15 +776,14 @@ void LocalVariableMap::intersectBackEdge(Context C1, Context C2) {
769776
const unsigned *I2 = C2.lookup(P.first);
770777
if (!I2) {
771778
// Variable does not exist at the end of the loop, invalidate.
772-
VDef->Ref = 0;
779+
VDef->invalidateRef();
773780
continue;
774781
}
775782

776783
// Compare the canonical IDs. This correctly handles chains of references
777784
// and determines if the variable is truly loop-invariant.
778-
if (getCanonicalDefinitionID(VDef->Ref) != getCanonicalDefinitionID(*I2)) {
779-
VDef->Ref = 0; // Mark this variable as undefined
780-
}
785+
if (VDef->CanonicalRef != getCanonicalDefinitionID(*I2))
786+
VDef->invalidateRef(); // Mark this variable as undefined
781787
}
782788
}
783789

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20107,9 +20107,10 @@ static void DoMarkVarDeclReferenced(
2010720107
bool NeededForConstantEvaluation =
2010820108
isPotentiallyConstantEvaluatedContext(SemaRef) && UsableInConstantExpr;
2010920109

20110-
bool NeedDefinition = OdrUse == OdrUseContext::Used ||
20111-
NeededForConstantEvaluation ||
20112-
Var->getType()->isUndeducedType();
20110+
bool NeedDefinition =
20111+
OdrUse == OdrUseContext::Used || NeededForConstantEvaluation ||
20112+
(TSK != clang::TSK_Undeclared && !UsableInConstantExpr &&
20113+
Var->getType()->isUndeducedType());
2011320114

2011420115
assert(!isa<VarTemplatePartialSpecializationDecl>(Var) &&
2011520116
"Can't instantiate a partial template specialization.");

clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
14281428
DeclareImplicitDeductionGuidesForTypeAlias(*this, AliasTemplate, Loc);
14291429
return;
14301430
}
1431-
if (CXXRecordDecl *DefRecord =
1432-
cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) {
1431+
CXXRecordDecl *DefRecord =
1432+
dyn_cast_or_null<CXXRecordDecl>(Template->getTemplatedDecl());
1433+
if (!DefRecord)
1434+
return;
1435+
if (const CXXRecordDecl *Definition = DefRecord->getDefinition()) {
14331436
if (TemplateDecl *DescribedTemplate =
1434-
DefRecord->getDescribedClassTemplate())
1437+
Definition->getDescribedClassTemplate())
14351438
Template = DescribedTemplate;
14361439
}
14371440

clang/test/CIR/IR/alloca.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// RUN: cir-opt %s | FileCheck %s
2+
// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
33

44
!u64i = !cir.int<u, 64>
55
!u8i = !cir.int<u, 8>

clang/test/CIR/IR/array-ctor.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// RUN: cir-opt %s | FileCheck %s
2+
// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
33

44
!u8i = !cir.int<u, 8>
55
!rec_S = !cir.record<struct "S" padded {!u8i}>

clang/test/CIR/IR/array-dtor.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: cir-opt %s | FileCheck %s
1+
// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
22

33
!u8i = !cir.int<u, 8>
44
!rec_S = !cir.record<struct "S" padded {!u8i}>

clang/test/CIR/IR/array.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: cir-opt %s | FileCheck %s
1+
// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
22

33
!s32i = !cir.int<s, 32>
44

clang/test/CIR/IR/atomic.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: cir-opt %s | FileCheck %s
1+
// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
22

33
!s32i = !cir.int<s, 32>
44
!u32i = !cir.int<u, 32>

clang/test/CIR/IR/binassign.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: cir-opt %s | cir-opt | FileCheck %s
1+
// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
22

33
!s32i = !cir.int<s, 32>
44
!s8i = !cir.int<s, 8>

0 commit comments

Comments
 (0)