OSDN Git Service

[MetaRenamer] Leave `@main` alone.
authorDavide Italiano <davide@freebsd.org>
Tue, 1 Aug 2017 05:14:45 +0000 (05:14 +0000)
committerDavide Italiano <davide@freebsd.org>
Tue, 1 Aug 2017 05:14:45 +0000 (05:14 +0000)
To the best of my knowledge -metarenamer is used in two cases:
1) obfuscate names, when e.g. they contain informations that
can't be shared.
2) Improve clarity of the textual IR for testcases.

One of the usecases if getting the output of `opt` and passing it
to the lli interpreter to run the test. If metarenamer renames
@main, lli can't find an entry point.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309657 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/MetaRenamer.cpp
test/Transforms/MetaRenamer/main.ll [new file with mode: 0644]

index 9f2ad54..9af9d5f 100644 (file)
@@ -123,7 +123,11 @@ namespace {
             TLI.getLibFunc(F, Tmp))
           continue;
 
-        F.setName(renamer.newName());
+        // Leave @main alone. The output of -metarenamer might be passed to
+        // lli for execution and the latter needs a main entry point.
+        if (Name != "main")
+          F.setName(renamer.newName());
+
         runOnFunction(F);
       }
       return true;
diff --git a/test/Transforms/MetaRenamer/main.ll b/test/Transforms/MetaRenamer/main.ll
new file mode 100644 (file)
index 0000000..f11d70f
--- /dev/null
@@ -0,0 +1,15 @@
+; Make sure @main is left untouched.
+; RUN: opt -metarenamer -S %s | FileCheck %s
+
+; CHECK: define void @main
+; CHECK: call void @main
+
+define void @main() {
+  call void @patatino()
+  ret void
+}
+
+define void @patatino() {
+  call void @main()
+  ret void
+}