Skip to content

Commit e368e4d

Browse files
author
Anastasia Stulova
committed
Fix ICE on reference binding with mismatching addr spaces.
When we attempt to add an addr space qual to a type already qualified by an addr space ICE is triggered. Before creating a type with new address space, remove the old addr space. Fixing PR38614! Differential Revision: https://reviews.llvm.org/D57524 llvm-svn: 353160
1 parent 84ca706 commit e368e4d

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,19 +4670,23 @@ static void TryReferenceInitializationCore(Sema &S,
46704670
// applied.
46714671
// Postpone address space conversions to after the temporary materialization
46724672
// conversion to allow creating temporaries in the alloca address space.
4673-
auto AS1 = T1Quals.getAddressSpace();
4674-
auto AS2 = T2Quals.getAddressSpace();
4675-
T1Quals.removeAddressSpace();
4676-
T2Quals.removeAddressSpace();
4677-
QualType cv1T4 = S.Context.getQualifiedType(cv2T2, T1Quals);
4678-
if (T1Quals != T2Quals)
4673+
auto T1QualsIgnoreAS = T1Quals;
4674+
auto T2QualsIgnoreAS = T2Quals;
4675+
if (T1Quals.getAddressSpace() != T2Quals.getAddressSpace()) {
4676+
T1QualsIgnoreAS.removeAddressSpace();
4677+
T2QualsIgnoreAS.removeAddressSpace();
4678+
}
4679+
QualType cv1T4 = S.Context.getQualifiedType(cv2T2, T1QualsIgnoreAS);
4680+
if (T1QualsIgnoreAS != T2QualsIgnoreAS)
46794681
Sequence.AddQualificationConversionStep(cv1T4, ValueKind);
46804682
Sequence.AddReferenceBindingStep(cv1T4, ValueKind == VK_RValue);
46814683
ValueKind = isLValueRef ? VK_LValue : VK_XValue;
4682-
if (AS1 != AS2) {
4683-
T1Quals.addAddressSpace(AS1);
4684-
QualType cv1AST4 = S.Context.getQualifiedType(cv2T2, T1Quals);
4685-
Sequence.AddQualificationConversionStep(cv1AST4, ValueKind);
4684+
// Add addr space conversion if required.
4685+
if (T1Quals.getAddressSpace() != T2Quals.getAddressSpace()) {
4686+
auto T4Quals = cv1T4.getQualifiers();
4687+
T4Quals.addAddressSpace(T1Quals.getAddressSpace());
4688+
QualType cv1T4WithAS = S.Context.getQualifiedType(T2, T4Quals);
4689+
Sequence.AddQualificationConversionStep(cv1T4WithAS, ValueKind);
46864690
}
46874691

46884692
// In any case, the reference is bound to the resulting glvalue (or to
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
2+
// expected-no-diagnostics
3+
4+
// Extract from PR38614
5+
struct C {};
6+
7+
C f1() {
8+
return C{};
9+
}
10+
11+
C f2(){
12+
C c;
13+
return c;
14+
}

0 commit comments

Comments
 (0)