<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 20, 2021 at 11:52 AM Nikita Popov <<a href="mailto:nikita.ppv@gmail.com">nikita.ppv@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 20, 2021 at 8:27 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Any chance some of this series of patches could have test coverage included? (like small clang test cases that exercise only a narrow part of the codegen & works with force-opaque-pointers due to these changes?)<br></div></blockquote><div><br></div><div>I think we're still pretty far away from any meaningful opaque pointer testing with clang. We need at least <a href="https://reviews.llvm.org/D103465" target="_blank">https://reviews.llvm.org/D103465</a> to land to support even basic cases.<br></div><div><br></div><div>I just ran a quick test, and while an empty main() works under -mllvm -force-opaque-pointers, </div></div></div></blockquote><div><br>That seems like something we could test/start things along, but yeah - presumably that's always worked (by not having any pointers at all), so isn't interesting.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>you get an assertion as soon as you try to dereference a pointer.<br></div></div></div></blockquote><div><br>*nod* Just ran some tests too - having parameters (including pointer parameters, such as "int main(int argc, char** argv) { }") work OK, but yeah, soon as you try to access any variable (global or local), it trips up.<br><br>Thanks for the thoughts. <br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div><div><br></div><div>Nikita<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jul 17, 2021 at 9:48 AM Nikita Popov via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Nikita Popov<br>
Date: 2021-07-17T18:48:21+02:00<br>
New Revision: 4ace6008f2fde781c1bedc7515e6380e449cb56a<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/4ace6008f2fde781c1bedc7515e6380e449cb56a" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/4ace6008f2fde781c1bedc7515e6380e449cb56a</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/4ace6008f2fde781c1bedc7515e6380e449cb56a.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/4ace6008f2fde781c1bedc7515e6380e449cb56a.diff</a><br>
<br>
LOG: [OpaquePtr] Remove uses of CreateStructGEP() without element type<br>
<br>
Remove uses of to-be-deprecated API.<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
    clang/lib/CodeGen/CGBlocks.cpp<br>
    clang/lib/CodeGen/CGObjCGNU.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp<br>
index 769501a036e6..f39a56f81d41 100644<br>
--- a/clang/lib/CodeGen/CGBlocks.cpp<br>
+++ b/clang/lib/CodeGen/CGBlocks.cpp<br>
@@ -1375,7 +1375,7 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,<br>
     llvm::IRBuilder<> b(llvm::BasicBlock::Create(CGM.getLLVMContext(), "entry",<br>
           Init));<br>
     b.CreateAlignedStore(CGM.getNSConcreteGlobalBlock(),<br>
-                         b.CreateStructGEP(literal, 0),<br>
+                         b.CreateStructGEP(literal->getValueType(), literal, 0),<br>
                          CGM.getPointerAlign().getAsAlign());<br>
     b.CreateRetVoid();<br>
     // We can't use the normal LLVM global initialisation array, because we<br>
<br>
diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp<br>
index 9e47dbf7bdf1..3f361f4e7931 100644<br>
--- a/clang/lib/CodeGen/CGObjCGNU.cpp<br>
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp<br>
@@ -945,7 +945,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {<br>
   /// Generate the name of a symbol for a reference to a class.  Accesses to<br>
   /// classes should be indirected via this.<br>
<br>
-  typedef std::pair<std::string, std::pair<llvm::Constant*, int>> EarlyInitPair;<br>
+  typedef std::pair<std::string, std::pair<llvm::GlobalVariable*, int>><br>
+      EarlyInitPair;<br>
   std::vector<EarlyInitPair> EarlyInitList;<br>
<br>
   std::string SymbolForClassRef(StringRef Name, bool isWeak) {<br>
@@ -1096,7 +1097,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {<br>
         }<br>
       }<br>
     }<br>
-    auto *ObjCStrGV =<br>
+    llvm::GlobalVariable *ObjCStrGV =<br>
       Fields.finishAndCreateGlobal(<br>
           isNamed ? StringRef(StringName) : ".objc_string",<br>
           Align, false, isNamed ? llvm::GlobalValue::LinkOnceODRLinkage<br>
@@ -1107,7 +1108,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {<br>
       ObjCStrGV->setVisibility(llvm::GlobalValue::HiddenVisibility);<br>
     }<br>
     if (CGM.getTriple().isOSBinFormatCOFF()) {<br>
-      std::pair<llvm::Constant*, int> v{ObjCStrGV, 0};<br>
+      std::pair<llvm::GlobalVariable*, int> v{ObjCStrGV, 0};<br>
       EarlyInitList.emplace_back(Sym, v);<br>
     }<br>
     llvm::Constant *ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStrGV, IdTy);<br>
@@ -1654,9 +1655,10 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {<br>
       for (const auto &lateInit : EarlyInitList) {<br>
         auto *global = TheModule.getGlobalVariable(lateInit.first);<br>
         if (global) {<br>
+          llvm::GlobalVariable *GV = lateInit.second.first;<br>
           b.CreateAlignedStore(<br>
               global,<br>
-              b.CreateStructGEP(lateInit.second.first, lateInit.second.second),<br>
+              b.CreateStructGEP(GV->getValueType(), GV, lateInit.second.second),<br>
               CGM.getPointerAlign().getAsAlign());<br>
         }<br>
       }<br>
@@ -1938,7 +1940,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {<br>
     // struct objc_property_list *properties<br>
     classFields.add(GeneratePropertyList(OID, classDecl));<br>
<br>
-    auto *classStruct =<br>
+    llvm::GlobalVariable *classStruct =<br>
       classFields.finishAndCreateGlobal(SymbolForClass(className),<br>
         CGM.getPointerAlign(), false, llvm::GlobalValue::ExternalLinkage);<br>
<br>
@@ -1949,12 +1951,12 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {<br>
     if (IsCOFF) {<br>
       // we can't import a class struct.<br>
       if (OID->getClassInterface()->hasAttr<DLLExportAttr>()) {<br>
-        cast<llvm::GlobalValue>(classStruct)->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);<br>
+        classStruct->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);<br>
         cast<llvm::GlobalValue>(classRefSymbol)->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);<br>
       }<br>
<br>
       if (SuperClass) {<br>
-        std::pair<llvm::Constant*, int> v{classStruct, 1};<br>
+        std::pair<llvm::GlobalVariable*, int> v{classStruct, 1};<br>
         EarlyInitList.emplace_back(std::string(SuperClass->getName()),<br>
                                    std::move(v));<br>
       }<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</blockquote></div></div>
</blockquote></div></div>