Handle inlining of newMessageInfo()

Bug: 112437944
Change-Id: I8db1a5800ce0a3f35d09999c6a04c3edc72c4823
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/proto/GeneratedMessageLiteShrinker.java b/src/main/java/com/android/tools/r8/ir/analysis/proto/GeneratedMessageLiteShrinker.java
index 7f33fbb..dbd95ae 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/proto/GeneratedMessageLiteShrinker.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/proto/GeneratedMessageLiteShrinker.java
@@ -19,6 +19,7 @@
 import com.android.tools.r8.ir.code.IRCode;
 import com.android.tools.r8.ir.code.Instruction;
 import com.android.tools.r8.ir.code.InstructionListIterator;
+import com.android.tools.r8.ir.code.InvokeMethod;
 import com.android.tools.r8.ir.code.InvokeStatic;
 import com.android.tools.r8.ir.code.MemberType;
 import com.android.tools.r8.ir.code.NewArrayEmpty;
@@ -73,21 +74,16 @@
       return;
     }
 
-    InvokeStatic newMessageInfoInvoke = null;
+    InvokeMethod newMessageInfoInvoke = null;
     for (Instruction instruction : code.instructions()) {
       if (instruction.isInvokeStatic()) {
         InvokeStatic invoke = instruction.asInvokeStatic();
-        if (invoke.getInvokedMethod() == references.newMessageInfoMethod) {
+        if (invoke.getInvokedMethod() == references.newMessageInfoMethod
+            || invoke.getInvokedMethod() == references.rawMessageInfoConstructor) {
           newMessageInfoInvoke = invoke;
           break;
         }
       }
-
-      // Implicitly check that the method newMessageInfo() has not been inlined. In that case,
-      // we would need to rewrite the const-string instructions that flow into the constructor
-      // of com.google.protobuf.RawMessageInfo.
-      assert !instruction.isNewInstance()
-          || instruction.asNewInstance().clazz != references.rawMessageInfoType;
     }
 
     if (newMessageInfoInvoke != null) {
@@ -113,7 +109,7 @@
   private void rewriteArgumentsToNewMessageInfo(
       DexEncodedMethod method,
       IRCode code,
-      InvokeStatic newMessageInfoInvoke,
+      InvokeMethod newMessageInfoInvoke,
       Value infoValue,
       ProtoMessageInfo protoMessageInfo) {
     rewriteInfoArgumentToNewMessageInfo(code, infoValue, protoMessageInfo);
@@ -130,7 +126,7 @@
   private void rewriteObjectsArgumentToNewMessageInfo(
       DexEncodedMethod method,
       IRCode code,
-      InvokeStatic newMessageInfoInvoke,
+      InvokeMethod newMessageInfoInvoke,
       ProtoMessageInfo protoMessageInfo) {
     // Position iterator immediately before the call to newMessageInfo().
     BasicBlock block = newMessageInfoInvoke.getBlock();
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/proto/ProtoReferences.java b/src/main/java/com/android/tools/r8/ir/analysis/proto/ProtoReferences.java
index 1dd0961..85b1590 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/proto/ProtoReferences.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/proto/ProtoReferences.java
@@ -27,6 +27,7 @@
   public final DexProto findLiteExtensionByNumberProto;
 
   public final DexMethod newMessageInfoMethod;
+  public final DexMethod rawMessageInfoConstructor;
 
   public ProtoReferences(DexItemFactory factory) {
     // Types.
@@ -65,6 +66,12 @@
             factory.createProto(
                 factory.objectType, messageLiteType, factory.stringType, factory.objectArrayType),
             factory.createString("newMessageInfo"));
+    rawMessageInfoConstructor =
+        factory.createMethod(
+            rawMessageInfoType,
+            factory.createProto(
+                factory.voidType, messageLiteType, factory.stringType, factory.objectArrayType),
+            factory.constructorMethodName);
   }
 
   public boolean isDynamicMethod(DexMethod method) {
diff --git a/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java b/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java
index 2971cf9..6a79796 100644
--- a/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java
+++ b/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java
@@ -39,9 +39,6 @@
         .addProgramFiles(PROTO2_EXAMPLES_JAR, PROTO2_PROTO_JAR, PROTOBUF_LITE_JAR)
         .addKeepMainRule("proto2.TestClass")
         .addKeepRules(
-            // TODO(b/112437944): Should rewrite constructor calls to RawMessageInfo when
-            //  newMessageInfo() is inlined.
-            "-neverinline class * { newMessageInfo(...); }",
             // TODO(b/112437944): Do not remove proto fields that are actually used in tree shaking.
             "-keepclassmembers,allowobfuscation class * extends",
             "    com.google.protobuf.GeneratedMessageLite {",