80 lines · c
1// XFAIL: target={{.*}}-aix{{.*}}2// RUN: %clang_profgen -DCHECK_SYMBOLS -O3 -o %t.symbols %s3// RUN: llvm-nm %t.symbols | FileCheck %s --check-prefix=CHECK-SYMBOLS4// RUN: %clang_profgen -O3 -o %t %s5// RUN: %run %t %t.profraw6// RUN: llvm-profdata merge -o %t.profdata %t.profraw7// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s8 9// This usage of llvm-nm assumes executables have symbol tables. They do not in10// an MSVC environment, so we can't make this test portable.11// UNSUPPORTED: target={{.*msvc.*}}12 13// The MinGW CRT init files do reference malloc etc, so this test fails.14// UNSUPPORTED: target={{.*windows-gnu.*}}15 16#include <stdint.h>17#include <stdlib.h>18 19#ifndef CHECK_SYMBOLS20#include <stdio.h>21#endif22 23int __llvm_profile_runtime = 0;24uint64_t __llvm_profile_get_size_for_buffer(void);25int __llvm_profile_write_buffer(char *);26int __llvm_profile_merge_from_buffer(const char *, uint64_t Size);27 28int write_buffer(uint64_t, const char *);29int main(int argc, const char *argv[]) {30 // CHECK-LABEL: define {{.*}} @main(31 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]32 if (argc < 2)33 return 1;34 35 const uint64_t MaxSize = 10000;36 static char Buffer[MaxSize];37 38 uint64_t Size = __llvm_profile_get_size_for_buffer();39 if (Size > MaxSize)40 return 1;41 int Write = __llvm_profile_write_buffer(Buffer);42 if (Write)43 return Write;44 45#ifdef CHECK_SYMBOLS46 // Don't write it out. Since we're checking the symbols, we don't have libc47 // available.48 // Call merge function to make sure it does not bring in libc deps:49 __llvm_profile_merge_from_buffer(Buffer, Size);50 return 0;51#else52 // Actually write it out so we can FileCheck the output.53 FILE *File = fopen(argv[1], "w");54 if (!File)55 return 1;56 if (fwrite(Buffer, 1, Size, File) != Size)57 return 1;58 return fclose(File);59#endif60}61// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}62 63// CHECK-SYMBOLS-NOT: {{ }}___cxx_global_var_init64// CHECK-SYMBOLS-NOT: {{ }}___llvm_profile_register_write_file_atexit65// CHECK-SYMBOLS-NOT: {{ }}___llvm_profile_set_filename66// CHECK-SYMBOLS-NOT: {{ }}___llvm_profile_write_file67// CHECK-SYMBOLS-NOT: {{ }}_fdopen68// CHECK-SYMBOLS-NOT: {{ }}_fopen69// CHECK-SYMBOLS-NOT: {{ }}_fwrite70// CHECK-SYMBOLS-NOT: {{ }}_getenv71// CHECK-SYMBOLS-NOT: {{ }}getenv72// CHECK-SYMBOLS-NOT: {{ }}_malloc73// CHECK-SYMBOLS-NOT: {{ }}malloc74// CHECK-SYMBOLS-NOT: {{ }}_calloc75// CHECK-SYMBOLS-NOT: {{ }}calloc76// CHECK-SYMBOLS-NOT: {{ }}_free77// CHECK-SYMBOLS-NOT: {{ }}free78// CHECK-SYMBOLS-NOT: {{ }}_open79// CHECK-SYMBOLS-NOT: {{ }}_getpagesize80