39 lines · c
1// REQUIRES: continuous-mode2 3// RUN: rm -rf %t.dir && mkdir -p %t.dir4//5// Note: %%p is needed here, not %p, because of lit's path substitution.6// RUN: %clang_profgen=%t.dir/-%%p -fprofile-continuous -o %t.exe %s7// RUN: %run %t.exe8// RUN: %clang_pgogen -fprofile-continuous -o %t.exe %s9// RUN: env LLVM_PROFILE_FILE="%t.dir/%c-%%p" %run %t.exe10 11#include <stdlib.h>12#include <string.h>13 14extern int __llvm_profile_is_continuous_mode_enabled(void);15extern const char *__llvm_profile_get_filename(void);16extern int getpid(void);17 18int main() {19 // Check that continuous mode is enabled.20 if (!__llvm_profile_is_continuous_mode_enabled())21 return 1;22 23 // Check that the PID is actually in the filename.24 const char *Filename = __llvm_profile_get_filename();25 26 int Len = strlen(Filename);27 --Len;28 while (Filename[Len] != '-')29 --Len;30 31 const char *PidStr = Filename + Len + 1;32 int Pid = atoi(PidStr);33 34 if (Pid != getpid())35 return 1;36 37 return 0;38}39