r373929 - Fix Calling Convention through aliases

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 7 10:28:04 PDT 2019


Author: erichkeane
Date: Mon Oct  7 10:28:03 2019
New Revision: 373929

URL: http://llvm.org/viewvc/llvm-project?rev=373929&view=rev
Log:
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

Added:
    cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp   (with props)
Modified:
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=373929&r1=373928&r2=373929&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Oct  7 10:28:03 2019
@@ -248,8 +248,8 @@ llvm::Function *CodeGenFunction::createA
   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();

Added: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp?rev=373929&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp Mon Oct  7 10:28:03 2019
@@ -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 at XZ" = dso_local unnamed_addr alias void (%struct.Derived*), bitcast (void (%struct.Base*)* @"??1Base@@UAE at XZ" to void (%struct.Derived*)*)
+
+// CHECK: define dso_local x86_thiscallcc void @"??1Base@@UAE at XZ"
+// CHECK: define internal void @"??__E?inst at Derived@@2U1 at A@@YAXXZ"
+// CHECK: call i32 @atexit(void ()* @"??__F?inst at Derived@@2U1 at A@@YAXXZ"
+//
+// CHECK: define internal void @"??__F?inst at Derived@@2U1 at A@@YAXXZ"
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call x86_thiscallcc void @"??1Derived@@UAE at XZ"

Propchange: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the cfe-commits mailing list