TomTan created this revision.
TomTan added reviewers: efriedma, rnk.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar.
Herald added a project: clang.

On Windows ARM64, intrinsic `__debugbreak` should be compiled into `brk 
#0xF000` which is different from llvm intrinsic `debugtrap` as `brk #0`. This 
change fixes this by transforming `__debugbreak` to the expected inline 
assembly in Clang.


Repository:
  rC Clang

https://reviews.llvm.org/D63617

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/ms-intrinsics.c


Index: test/CodeGen/ms-intrinsics.c
===================================================================
--- test/CodeGen/ms-intrinsics.c
+++ test/CodeGen/ms-intrinsics.c
@@ -1379,6 +1379,14 @@
 // CHECK-INTEL: call void asm sideeffect "int $$0x29", "{cx}"(i32 42) 
#[[NORETURN]]
 // CHECK-ARM64: call void asm sideeffect "brk #0xF003", "{w0}"(i32 42) 
#[[NORETURN:[0-9]+]]
 
+void test__debugbreak() {
+  __debugbreak();
+}
+// CHECK_LABEL: define{{.*}} void @test__debugbreak() {
+// CHECK-INTEL: call void @llvm.debugtrap()
+// CHECK-ARM: call void @llvm.debugtrap()
+// CHECK-ARM64: call void asm sideeffect "brk #0xF000", ""()
+
 // Attributes come last.
 
 // CHECK: attributes #[[NORETURN]] = { noreturn{{.*}} }
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -2125,8 +2125,20 @@
   }
   case Builtin::BI__builtin_trap:
     return RValue::get(EmitTrapCall(Intrinsic::trap));
-  case Builtin::BI__debugbreak:
-    return RValue::get(EmitTrapCall(Intrinsic::debugtrap));
+  case Builtin::BI__debugbreak: {
+    llvm::Triple::ArchType ISA = getTarget().getTriple().getArch();
+    switch (ISA) {
+    default:
+      return RValue::get(EmitTrapCall(Intrinsic::debugtrap));
+    case llvm::Triple::aarch64: {
+      llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
+      llvm::InlineAsm *IA =
+        llvm::InlineAsm::get(FTy, "brk #0xF000", "", /*SideEffects=*/true);
+      llvm::CallInst *CI = Builder.CreateCall(IA);
+      return RValue::get(CI);
+    }
+    }
+  }
   case Builtin::BI__builtin_unreachable: {
     EmitUnreachable(E->getExprLoc());
 


Index: test/CodeGen/ms-intrinsics.c
===================================================================
--- test/CodeGen/ms-intrinsics.c
+++ test/CodeGen/ms-intrinsics.c
@@ -1379,6 +1379,14 @@
 // CHECK-INTEL: call void asm sideeffect "int $$0x29", "{cx}"(i32 42) #[[NORETURN]]
 // CHECK-ARM64: call void asm sideeffect "brk #0xF003", "{w0}"(i32 42) #[[NORETURN:[0-9]+]]
 
+void test__debugbreak() {
+  __debugbreak();
+}
+// CHECK_LABEL: define{{.*}} void @test__debugbreak() {
+// CHECK-INTEL: call void @llvm.debugtrap()
+// CHECK-ARM: call void @llvm.debugtrap()
+// CHECK-ARM64: call void asm sideeffect "brk #0xF000", ""()
+
 // Attributes come last.
 
 // CHECK: attributes #[[NORETURN]] = { noreturn{{.*}} }
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -2125,8 +2125,20 @@
   }
   case Builtin::BI__builtin_trap:
     return RValue::get(EmitTrapCall(Intrinsic::trap));
-  case Builtin::BI__debugbreak:
-    return RValue::get(EmitTrapCall(Intrinsic::debugtrap));
+  case Builtin::BI__debugbreak: {
+    llvm::Triple::ArchType ISA = getTarget().getTriple().getArch();
+    switch (ISA) {
+    default:
+      return RValue::get(EmitTrapCall(Intrinsic::debugtrap));
+    case llvm::Triple::aarch64: {
+      llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
+      llvm::InlineAsm *IA =
+        llvm::InlineAsm::get(FTy, "brk #0xF000", "", /*SideEffects=*/true);
+      llvm::CallInst *CI = Builder.CreateCall(IA);
+      return RValue::get(CI);
+    }
+    }
+  }
   case Builtin::BI__builtin_unreachable: {
     EmitUnreachable(E->getExprLoc());
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to