summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2019-10-07 17:28:03 +0000
committerErich Keane <erich.keane@intel.com>2019-10-07 17:28:03 +0000
commit8a410bcef02c25b6b3a49fa6483875eb64539aad (patch)
tree5bc0735b4fa2e26032f327aebacd2fd0d689715c /clang
parente4cec2d3c73f7b30edc03b6b8219273fc81fc477 (diff)
downloadbcm5719-llvm-8a410bcef02c25b6b3a49fa6483875eb64539aad.tar.gz
bcm5719-llvm-8a410bcef02c25b6b3a49fa6483875eb64539aad.zip
Fix Calling Convention through aliases
r369697 changed the behavior of stripPointerCasts to no longer include aliases. However, the code in CGDeclCXX.cpp's createAtExitStub counted on the looking through aliases to properly set the calling convention of a call. The result of the change was that the calling convention mismatch of the call would be replaced with a llvm.trap, causing a runtime crash. Differential Revision: https://reviews.llvm.org/D68584 llvm-svn: 373929
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGDeclCXX.cpp4
-rw-r--r--clang/test/CodeGenCXX/call-conv-thru-alias.cpp21
2 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index a54e5dcfda2..bf16b7bec4b 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -248,8 +248,8 @@ llvm::Function *CodeGenFunction::createAtExitStub(const VarDecl &VD,
llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
// Make sure the call and the callee agree on calling convention.
- if (llvm::Function *dtorFn =
- dyn_cast<llvm::Function>(dtor.getCallee()->stripPointerCasts()))
+ if (auto *dtorFn = dyn_cast<llvm::Function>(
+ dtor.getCallee()->stripPointerCastsAndAliases()))
call->setCallingConv(dtorFn->getCallingConv());
CGF.FinishFunction();
diff --git a/clang/test/CodeGenCXX/call-conv-thru-alias.cpp b/clang/test/CodeGenCXX/call-conv-thru-alias.cpp
new file mode 100644
index 00000000000..5bd5c7dbc5c
--- /dev/null
+++ b/clang/test/CodeGenCXX/call-conv-thru-alias.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i686-windows-pc -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-passes %s | FileCheck %s
+
+struct Base { virtual ~Base(); };
+struct Derived : Base {
+ virtual ~Derived();
+ static Derived inst;
+};
+
+Base::~Base(){}
+Derived::~Derived(){}
+Derived Derived::inst;
+
+// CHECK: @"??1Derived@@UAE@XZ" = dso_local unnamed_addr alias void (%struct.Derived*), bitcast (void (%struct.Base*)* @"??1Base@@UAE@XZ" to void (%struct.Derived*)*)
+
+// CHECK: define dso_local x86_thiscallcc void @"??1Base@@UAE@XZ"
+// CHECK: define internal void @"??__E?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK: call i32 @atexit(void ()* @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+//
+// CHECK: define internal void @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call x86_thiscallcc void @"??1Derived@@UAE@XZ"
OpenPOWER on IntegriCloud