This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Emit elementtype attributes for indirect inline asm constraints
ClosedPublic

Authored by nikic on Jan 5 2022, 7:53 AM.

Details

Summary

This implements the clang side of D116531. The elementtype attribute is added for all indirect constraints (*) and tests are updated accordingly.

Diff Detail

Event Timeline

nikic created this revision.Jan 5 2022, 7:53 AM
nikic requested review of this revision.Jan 5 2022, 7:53 AM
aeubanks accepted this revision.Jan 5 2022, 2:05 PM
aeubanks added a subscriber: aeubanks.

thanks, check-clang passes with

diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 03839e00c7aa..94a3586199d1 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1734,6 +1734,15 @@ public:
     return Attrs.getParamStackAlignment(ArgNo);
   }
 
+  /// Extract the elementtype type for a call or parameter.
+  Type *getParamElementType(unsigned ArgNo) const {
+    if (auto *Ty = Attrs.getParamElementType(ArgNo))
+      return Ty;
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getParamElementType(ArgNo);
+    return nullptr;
+  }
+
   /// Extract the byval type for a call or parameter.
   Type *getParamByValType(unsigned ArgNo) const {
     if (auto *Ty = Attrs.getParamByValType(ArgNo))
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 254d7b2fdff4..0c515900dbb0 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2161,6 +2161,10 @@ void Verifier::verifyInlineAsmCall(const CallBase &Call) {
       Assert(Arg->getType()->isPointerTy(),
              "Operand for indirect constraint must have pointer type",
              &Call);
+      Assert(
+          cast<PointerType>(Arg->getType())
+              ->isOpaqueOrPointeeTypeMatches(Call.getParamElementType(ArgNo)),
+          "HI");
 
       // TODO: Require elementtype attribute here.
     } else {
This revision is now accepted and ready to land.Jan 5 2022, 2:05 PM
This revision was landed with ongoing or failed builds.Jan 6 2022, 12:29 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2022, 12:29 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript