Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LLVM 12.87 KB | None | 0 0
  1. Original source code:
  2. #include <stdio.h>
  3.  
  4. class TestClass {
  5. public:
  6.     TestClass(int _x, int _y) {
  7.         x = _x;
  8.         y = _y;
  9.     }
  10. private:
  11.     int x;
  12.     int y;
  13. };
  14.  
  15. int main()
  16. {
  17.  
  18.     char* buffer;
  19.     int size = 101;
  20.     buffer = new char[size];
  21.     printf("CHECK address: 0x%p, size: %d\n", buffer, size);
  22.     TestClass* test = new TestClass(1, 2);
  23.     printf("(CHECK address: 0x%p, size: %d\n", test, sizeof(TestClass));
  24.  
  25.     delete buffer;
  26.     delete test;
  27. }
  28. --------------------------------------
  29. IR after insrumentation:
  30.  
  31. ; ModuleID = '..\main.cpp'
  32. source_filename = "..\\main.cpp"
  33. target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
  34. target triple = "x86_64-pc-windows-msvc19.16.27035"
  35.  
  36. %class.TestClass = type { i32, i32 }
  37. %struct.__vcrt_assert_va_start_is_not_reference = type { i8 }
  38. %struct._iobuf = type { i8* }
  39. %struct.__crt_locale_pointers = type { %struct.__crt_locale_data*, %struct.__crt_multibyte_data* }
  40. %struct.__crt_locale_data = type opaque
  41. %struct.__crt_multibyte_data = type opaque
  42.  
  43. $printf = comdat any
  44.  
  45. $"??0TestClass@@QEAA@HH@Z" = comdat any
  46.  
  47. $_vfprintf_l = comdat any
  48.  
  49. $__local_stdio_printf_options = comdat any
  50.  
  51. $"??_C@_0BP@DNHBDPL@CHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = comdat any
  52.  
  53. $"??_C@_0CA@KKHCADGA@?$CICHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = comdat any
  54.  
  55. $"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA" = comdat any
  56.  
  57. @"??_C@_0BP@DNHBDPL@CHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [31 x i8] c"CHECK address: 0x%p, size: %d\0A\00", comdat, align 1
  58. @"??_C@_0CA@KKHCADGA@?$CICHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [32 x i8] c"(CHECK address: 0x%p, size: %d\0A\00", comdat, align 1
  59. @"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA" = linkonce_odr dso_local global i64 0, comdat, align 8
  60. @globalKey = internal global i64 0, align 8
  61. @0 = private unnamed_addr constant [46 x i8] c"Allocated address: 0x%p, size: %d, key: 0x%x\0A\00", align 1
  62. @1 = private unnamed_addr constant [46 x i8] c"Allocated address: 0x%p, size: %d, key: 0x%x\0A\00", align 1
  63.  
  64. ; Function Attrs: noinline norecurse optnone uwtable
  65. define dso_local i32 @main() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
  66. entry:
  67.   %retval = alloca i32, align 4
  68.   %buffer = alloca i8*, align 8
  69.   %size = alloca i32, align 4
  70.   %test = alloca %class.TestClass*, align 8
  71.   store i32 0, i32* %retval, align 4
  72.   store i32 101, i32* %size, align 4
  73.   %0 = load i32, i32* %size, align 4
  74.   %conv = sext i32 %0 to i64
  75.   %call = call noalias nonnull i8* @"??_U@YAPEAX_K@Z"(i64 %conv) #8
  76.   %1 = load i64, i64* @globalKey
  77.   %2 = add i64 %1, 1
  78.   store i64 %2, i64* @globalKey
  79.   %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @0, i32 0, i32 0), i8* %call, i64 %conv, i64 0)
  80.   store i8* %call, i8** %buffer, align 8
  81.   %4 = load i32, i32* %size, align 4
  82.   %5 = load i8*, i8** %buffer, align 8
  83.   %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @"??_C@_0BP@DNHBDPL@CHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@", i64 0, i64 0), i8* %5, i32 %4)
  84.   %call2 = call noalias nonnull i8* @"??2@YAPEAX_K@Z"(i64 8) #8
  85.   %6 = load i64, i64* @globalKey
  86.   %7 = add i64 %6, 1
  87.   store i64 %7, i64* @globalKey
  88.   %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @1, i32 0, i32 0), i8* %call2, i64 8, i64 0)
  89.   %9 = bitcast i8* %call2 to %class.TestClass*
  90.   %call3 = invoke %class.TestClass* @"??0TestClass@@QEAA@HH@Z"(%class.TestClass* %9, i32 1, i32 2)
  91.           to label %invoke.cont unwind label %ehcleanup
  92.  
  93. invoke.cont:                                      ; preds = %entry
  94.   store %class.TestClass* %9, %class.TestClass** %test, align 8
  95.   %10 = load %class.TestClass*, %class.TestClass** %test, align 8
  96.   %call4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @"??_C@_0CA@KKHCADGA@?$CICHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@", i64 0, i64 0), %class.TestClass* %10, i64 8)
  97.   %11 = load i8*, i8** %buffer, align 8
  98.   %isnull = icmp eq i8* %11, null
  99.   br i1 %isnull, label %delete.end, label %delete.notnull
  100.  
  101. delete.notnull:                                   ; preds = %invoke.cont
  102.   call void @"??3@YAXPEAX@Z"(i8* %11) #9
  103.   br label %delete.end
  104.  
  105. delete.end:                                       ; preds = %delete.notnull, %invoke.cont
  106.   %12 = load %class.TestClass*, %class.TestClass** %test, align 8
  107.   %isnull5 = icmp eq %class.TestClass* %12, null
  108.   br i1 %isnull5, label %delete.end7, label %delete.notnull6
  109.  
  110. delete.notnull6:                                  ; preds = %delete.end
  111.   %13 = bitcast %class.TestClass* %12 to i8*
  112.   call void @"??3@YAXPEAX@Z"(i8* %13) #9
  113.   br label %delete.end7
  114.  
  115. delete.end7:                                      ; preds = %delete.notnull6, %delete.end
  116.   %14 = load i32, i32* %retval, align 4
  117.   ret i32 %14
  118.  
  119. ehcleanup:                                        ; preds = %entry
  120.   %15 = cleanuppad within none []
  121.   call void @"??3@YAXPEAX@Z"(i8* %call2) #9 [ "funclet"(token %15) ]
  122.   cleanupret from %15 unwind to caller
  123. }
  124.  
  125. ; Function Attrs: nobuiltin allocsize(0)
  126. declare dso_local nonnull i8* @"??_U@YAPEAX_K@Z"(i64 %0) #1
  127.  
  128. ; Function Attrs: nobuiltin noinline optnone uwtable
  129. define linkonce_odr dso_local i32 @printf(i8* %_Format, ...) #2 comdat {
  130. entry:
  131.   %_Format.addr = alloca i8*, align 8
  132.   %_Result = alloca i32, align 4
  133.   %_ArgList = alloca i8*, align 8
  134.   %agg.tmp.ensured = alloca %struct.__vcrt_assert_va_start_is_not_reference, align 1
  135.   store i8* %_Format, i8** %_Format.addr, align 8
  136.   %_ArgList1 = bitcast i8** %_ArgList to i8*
  137.   call void @llvm.va_start(i8* %_ArgList1)
  138.   %0 = load i8*, i8** %_ArgList, align 8
  139.   %1 = load i8*, i8** %_Format.addr, align 8
  140.   %call = call %struct._iobuf* @__acrt_iob_func(i32 1)
  141.   %call2 = call i32 @_vfprintf_l(%struct._iobuf* %call, i8* %1, %struct.__crt_locale_pointers* null, i8* %0)
  142.   store i32 %call2, i32* %_Result, align 4
  143.   store i8* null, i8** %_ArgList, align 8
  144.   %2 = load i32, i32* %_Result, align 4
  145.   ret i32 %2
  146. }
  147.  
  148. ; Function Attrs: nobuiltin allocsize(0)
  149. declare dso_local nonnull i8* @"??2@YAPEAX_K@Z"(i64 %0) #1
  150.  
  151. ; Function Attrs: noinline nounwind optnone uwtable
  152. define linkonce_odr dso_local %class.TestClass* @"??0TestClass@@QEAA@HH@Z"(%class.TestClass* returned %this, i32 %_x, i32 %_y) unnamed_addr #3 comdat align 2 {
  153. entry:
  154.   %_y.addr = alloca i32, align 4
  155.   %_x.addr = alloca i32, align 4
  156.   %this.addr = alloca %class.TestClass*, align 8
  157.   store i32 %_y, i32* %_y.addr, align 4
  158.   store i32 %_x, i32* %_x.addr, align 4
  159.   store %class.TestClass* %this, %class.TestClass** %this.addr, align 8
  160.   %this1 = load %class.TestClass*, %class.TestClass** %this.addr, align 8
  161.   %0 = load i32, i32* %_x.addr, align 4
  162.   %x = getelementptr inbounds %class.TestClass, %class.TestClass* %this1, i32 0, i32 0
  163.   store i32 %0, i32* %x, align 4
  164.   %1 = load i32, i32* %_y.addr, align 4
  165.   %y = getelementptr inbounds %class.TestClass, %class.TestClass* %this1, i32 0, i32 1
  166.   store i32 %1, i32* %y, align 4
  167.   ret %class.TestClass* %this1
  168. }
  169.  
  170. declare dso_local i32 @__CxxFrameHandler3(...)
  171.  
  172. ; Function Attrs: nobuiltin nounwind
  173. declare dso_local void @"??3@YAXPEAX@Z"(i8* %0) #4
  174.  
  175. ; Function Attrs: nounwind
  176. declare void @llvm.va_start(i8* %0) #5
  177.  
  178. ; Function Attrs: noinline optnone uwtable
  179. define linkonce_odr dso_local i32 @_vfprintf_l(%struct._iobuf* %_Stream, i8* %_Format, %struct.__crt_locale_pointers* %_Locale, i8* %_ArgList) #6 comdat {
  180. entry:
  181.   %_ArgList.addr = alloca i8*, align 8
  182.   %_Locale.addr = alloca %struct.__crt_locale_pointers*, align 8
  183.   %_Format.addr = alloca i8*, align 8
  184.   %_Stream.addr = alloca %struct._iobuf*, align 8
  185.   store i8* %_ArgList, i8** %_ArgList.addr, align 8
  186.   store %struct.__crt_locale_pointers* %_Locale, %struct.__crt_locale_pointers** %_Locale.addr, align 8
  187.   store i8* %_Format, i8** %_Format.addr, align 8
  188.   store %struct._iobuf* %_Stream, %struct._iobuf** %_Stream.addr, align 8
  189.   %0 = load i8*, i8** %_ArgList.addr, align 8
  190.   %1 = load %struct.__crt_locale_pointers*, %struct.__crt_locale_pointers** %_Locale.addr, align 8
  191.   %2 = load i8*, i8** %_Format.addr, align 8
  192.   %3 = load %struct._iobuf*, %struct._iobuf** %_Stream.addr, align 8
  193.   %4 = load i64, i64* %call, align 8
  194.   %call1 = call i32 @__stdio_common_vfprintf(i64 %4, %struct._iobuf* %3, i8* %2, %struct.__crt_locale_pointers* %1, i8* %0)
  195.   ret i32 %call1
  196. }
  197.  
  198. declare dso_local %struct._iobuf* @__acrt_iob_func(i32 %0) #7
  199.  
  200. declare dso_local i32 @__stdio_common_vfprintf(i64 %0, %struct._iobuf* %1, i8* %2, %struct.__crt_locale_pointers* %3, i8* %4) #7
  201.  
  202. ; Function Attrs: noinline nounwind optnone uwtable
  203. define linkonce_odr dso_local i64* @__local_stdio_printf_options() #3 comdat {
  204. entry:
  205.   ret i64* @"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA"
  206. }
  207.  
  208. attributes #0 = { noinline norecurse optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
  209. attributes #1 = { nobuiltin allocsize(0) "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
  210. attributes #2 = { nobuiltin noinline optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
  211. attributes #3 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
  212. attributes #4 = { nobuiltin nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
  213. attributes #5 = { nounwind }
  214. attributes #6 = { noinline optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
  215. attributes #7 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
  216. attributes #8 = { builtin allocsize(0) }
  217. attributes #9 = { builtin nounwind }
  218.  
  219. !llvm.linker.options = !{!0}
  220. !llvm.module.flags = !{!1, !2}
  221. !llvm.ident = !{!3}
  222.  
  223. !0 = !{!"/FAILIFMISMATCH:\22_CRT_STDIO_ISO_WIDE_SPECIFIERS=0\22"}
  224. !1 = !{i32 1, !"wchar_size", i32 2}
  225. !2 = !{i32 7, !"PIC Level", i32 2}
  226. !3 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 259238baa659f85d57d6f9bb07a166b6dcf041dd)"}
  227. --------------------------------------
  228. Program output (after instrumentation):
  229.  
  230. Allocated address: 0x0000019614A01B20, size: 101, key: 0x0
  231. CHECK address: 0x0000019614A01B20, size: 101
  232. Allocated address: 0x0000019614A01B90, size: 8, key: 0x0
  233. CHECK address: 0x0000019614A01B90, size: 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement