[libcxx-commits] [libcxx] r363092 - Check in test that demonstrates ABI break for std::function.

Eric Fiselier via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 11 11:41:47 PDT 2019


Author: ericwf
Date: Tue Jun 11 11:41:47 2019
New Revision: 363092

URL: http://llvm.org/viewvc/llvm-project?rev=363092&view=rev
Log:
Check in test that demonstrates ABI break for std::function.

Our C++03 and C++11 implementations of function are not ABI
compatible. I've added a "test" that demonstrates this.

Added:
    libcxx/trunk/test/libcxx/utilities/function.objects/abi_bug_cxx03_cxx11_example.sh.cpp

Added: libcxx/trunk/test/libcxx/utilities/function.objects/abi_bug_cxx03_cxx11_example.sh.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/function.objects/abi_bug_cxx03_cxx11_example.sh.cpp?rev=363092&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/utilities/function.objects/abi_bug_cxx03_cxx11_example.sh.cpp (added)
+++ libcxx/trunk/test/libcxx/utilities/function.objects/abi_bug_cxx03_cxx11_example.sh.cpp Tue Jun 11 11:41:47 2019
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: clang
+// XFAIL: *
+
+// This tests is meant to demonstrate an existing ABI bug between the
+// C++03 and C++11 implementations of std::function. It is not a real test.
+
+// RUN: %cxx -c %s -o %t.first.o %flags %compile_flags -std=c++03 -g
+// RUN: %cxx -c %s -o %t.second.o -DWITH_MAIN %flags %compile_flags -g -std=c++11
+// RUN: %cxx -o %t.exe %t.first.o %t.second.o %flags %link_flags -g
+// RUN: %run
+
+#include <functional>
+#include <cassert>
+
+typedef std::function<void(int)> Func;
+
+Func CreateFunc();
+
+#ifndef WITH_MAIN
+// In C++03, the functions call operator, which is a part of the vtable,
+// is defined as 'void operator()(int)', but in C++11 it's
+// void operator()(int&&)'. So when the C++03 version is passed to C++11 code
+// the value of the integer is interpreted as its address.
+void test(int x) {
+  assert(x == 42);
+}
+Func CreateFunc() {
+  Func f(&test);
+  return f;
+}
+#else
+int main() {
+  Func f = CreateFunc();
+  f(42);
+}
+#endif




More information about the libcxx-commits mailing list