[PATCH] D122954: [clang] Extend target_clones tests to exercise declarations that are not definitions.

Tom Honermann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 2 14:11:33 PDT 2022


tahonermann created this revision.
tahonermann added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
tahonermann added inline comments.
tahonermann published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.


================
Comment at: clang/test/CodeGen/attr-target-clones.c:3
 // RUN: %clang_cc1 -triple x86_64-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefixes=WINDOWS,CHECK
+// XFAIL: *
 
----------------
The code changes needed for the test to again pass are in D122958.


================
Comment at: clang/test/CodeGen/attr-target-clones.c:134-138
+// LINUX: declare i32 @foo_used_no_defn.default.1()
+// LINUX: declare i32 ()* @foo_used_no_defn.resolver()
+
+// WINDOWS: declare dso_local i32 @foo_used_no_defn.default.1()
+// WINDOWS: declare dso_local i32 @foo_used_no_defn()
----------------
These checks illustrate the problem that causes the test to fail; resolver declarations are emitted, but definitions are not.


This change expands the existing code generation test for the 'target_clones'
attribute to cover uses of multiversion function declarations that lack
definitions. The newly added tests trigger a failure in LLVM IR verification
and the test is therefore marked as an expected failure pending a fix. Adding
'-disable-llvm-verifier' to the RUN lines of the test suffices for the test to
pass with the added annotations. The annotations for the new tests demonstrate
an additional deficiency; that a definition for the resolver function is not
emitted if a definition of the 'target_clones' function is not present.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122954

Files:
  clang/test/CodeGen/attr-target-clones.c


Index: clang/test/CodeGen/attr-target-clones.c
===================================================================
--- clang/test/CodeGen/attr-target-clones.c
+++ clang/test/CodeGen/attr-target-clones.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=LINUX,CHECK
 // RUN: %clang_cc1 -triple x86_64-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefixes=WINDOWS,CHECK
+// XFAIL: *
 
 // LINUX: $foo.resolver = comdat any
 // LINUX: $foo_dupes.resolver = comdat any
@@ -18,6 +19,7 @@
 // LINUX: @unused.ifunc = weak_odr ifunc void (), void ()* ()* @unused.resolver
 // LINUX: @foo_inline.ifunc = weak_odr ifunc i32 (), i32 ()* ()* @foo_inline.resolver
 // LINUX: @foo_inline2.ifunc = weak_odr ifunc i32 (), i32 ()* ()* @foo_inline2.resolver
+// LINUX: @foo_used_no_defn.ifunc = weak_odr ifunc i32 (), i32 ()* ()* @foo_used_no_defn.resolver
 
 int __attribute__((target_clones("sse4.2, default"))) foo(void) { return 0; }
 // LINUX: define {{.*}}i32 @foo.sse4.2.0()
@@ -115,6 +117,28 @@
 // WINDOWS: musttail call i32 @foo_inline2.sse4.2.1
 // WINDOWS: musttail call i32 @foo_inline2.default.2
 
+
+int __attribute__((target_clones("default", "sse4.2")))
+foo_unused_no_defn(void);
+
+int __attribute__((target_clones("default", "sse4.2")))
+foo_used_no_defn(void);
+
+int test_foo_used_no_defn(void) {
+  // LINUX: define {{.*}}i32 @test_foo_used_no_defn()
+  // WINDOWS: define dso_local i32 @test_foo_used_no_defn()
+  return foo_used_no_defn();
+  // LINUX: call i32 @foo_used_no_defn.ifunc()
+  // WINDOWS: call i32 @foo_used_no_defn()
+}
+// LINUX: declare i32 @foo_used_no_defn.default.1()
+// LINUX: declare i32 ()* @foo_used_no_defn.resolver()
+
+// WINDOWS: declare dso_local i32 @foo_used_no_defn.default.1()
+// WINDOWS: declare dso_local i32 @foo_used_no_defn()
+
+
+// Deferred emission of inline definitions.
 // LINUX: define linkonce i32 @foo_inline.arch_sandybridge.0() #[[SB]]
 // LINUX: define linkonce i32 @foo_inline.default.2() #[[DEF]]
 // LINUX: define linkonce i32 @foo_inline.sse4.2.1() #[[SSE42:[0-9]+]]
@@ -130,6 +154,7 @@
 // WINDOWS: define linkonce_odr dso_local i32 @foo_inline2.default.2() #[[DEF]]
 // WINDOWS: define linkonce_odr dso_local i32 @foo_inline2.sse4.2.1() #[[SSE42]]
 
+
 // CHECK: attributes #[[SSE42]] =
 // CHECK-SAME: "target-features"="+crc32,+cx8,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
 // CHECK: attributes #[[DEF]] =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122954.419913.patch
Type: text/x-patch
Size: 2461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220402/e52ba7de/attachment-0001.bin>


More information about the cfe-commits mailing list