[PATCH] D57524: Fix ICE on attempt to add an addr space qual to a type qualified by an addr space

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 5 03:32:46 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rC353160: Fix ICE on reference binding with mismatching addr spaces. (authored by stulova, committed by ).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D57524?vs=185024&id=185272#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57524/new/

https://reviews.llvm.org/D57524

Files:
  lib/Sema/SemaInit.cpp
  test/SemaOpenCLCXX/address-space-of-this.cl


Index: test/SemaOpenCLCXX/address-space-of-this.cl
===================================================================
--- test/SemaOpenCLCXX/address-space-of-this.cl
+++ test/SemaOpenCLCXX/address-space-of-this.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+// expected-no-diagnostics
+
+// Extract from PR38614
+struct C {};
+
+C f1() {
+ return C{};
+}
+
+C f2(){
+    C c;
+    return c;
+}
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4670,19 +4670,23 @@
     //   applied.
     // Postpone address space conversions to after the temporary materialization
     // conversion to allow creating temporaries in the alloca address space.
-    auto AS1 = T1Quals.getAddressSpace();
-    auto AS2 = T2Quals.getAddressSpace();
-    T1Quals.removeAddressSpace();
-    T2Quals.removeAddressSpace();
-    QualType cv1T4 = S.Context.getQualifiedType(cv2T2, T1Quals);
-    if (T1Quals != T2Quals)
+    auto T1QualsIgnoreAS = T1Quals;
+    auto T2QualsIgnoreAS = T2Quals;
+    if (T1Quals.getAddressSpace() != T2Quals.getAddressSpace()) {
+      T1QualsIgnoreAS.removeAddressSpace();
+      T2QualsIgnoreAS.removeAddressSpace();
+    }
+    QualType cv1T4 = S.Context.getQualifiedType(cv2T2, T1QualsIgnoreAS);
+    if (T1QualsIgnoreAS != T2QualsIgnoreAS)
       Sequence.AddQualificationConversionStep(cv1T4, ValueKind);
     Sequence.AddReferenceBindingStep(cv1T4, ValueKind == VK_RValue);
     ValueKind = isLValueRef ? VK_LValue : VK_XValue;
-    if (AS1 != AS2) {
-      T1Quals.addAddressSpace(AS1);
-      QualType cv1AST4 = S.Context.getQualifiedType(cv2T2, T1Quals);
-      Sequence.AddQualificationConversionStep(cv1AST4, ValueKind);
+    // Add addr space conversion if required.
+    if (T1Quals.getAddressSpace() != T2Quals.getAddressSpace()) {
+      auto T4Quals = cv1T4.getQualifiers();
+      T4Quals.addAddressSpace(T1Quals.getAddressSpace());
+      QualType cv1T4WithAS = S.Context.getQualifiedType(T2, T4Quals);
+      Sequence.AddQualificationConversionStep(cv1T4WithAS, ValueKind);
     }
 
     //   In any case, the reference is bound to the resulting glvalue (or to


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57524.185272.patch
Type: text/x-patch
Size: 2261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190205/8beaaf7b/attachment.bin>


More information about the cfe-commits mailing list