Clang Project

clang_source_code/test/CodeGen/nobuiltin.c
1// REQUIRES: x86-registered-target
2
3// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 -S -o - %s | FileCheck -check-prefix=STRCPY -check-prefix=MEMSET %s
4// RUN: %clang_cc1 -triple x86_64-linux-gnu -fno-builtin -O1 -S -o - %s | FileCheck -check-prefix=NOSTRCPY -check-prefix=NOMEMSET %s
5// RUN: %clang_cc1 -triple x86_64-linux-gnu -fno-builtin-memset -O1 -S -o - %s | FileCheck -check-prefix=STRCPY -check-prefix=NOMEMSET %s
6
7// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 -fexperimental-new-pass-manager -S -o - %s | FileCheck -check-prefix=STRCPY -check-prefix=MEMSET %s
8// RUN: %clang_cc1 -triple x86_64-linux-gnu -fno-builtin -O1 -fexperimental-new-pass-manager -S -o - %s | FileCheck -check-prefix=NOSTRCPY -check-prefix=NOMEMSET %s
9// RUN: %clang_cc1 -triple x86_64-linux-gnu -fno-builtin-memset -O1 -fexperimental-new-pass-manager -S -o - %s | FileCheck -check-prefix=STRCPY -check-prefix=NOMEMSET %s
10
11void PR13497() {
12  char content[2];
13  // make sure we don't optimize this call to strcpy()
14  // STRCPY-NOT: __strcpy_chk
15  // NOSTRCPY: __strcpy_chk
16  __builtin___strcpy_chk(content, "", 1);
17}
18
19void PR4941(char *s) {
20  // Make sure we don't optimize this loop to a memset().
21  // NOMEMSET-NOT: memset
22  // MEMSET: memset
23  for (unsigned i = 0; i < 8192; ++i)
24    s[i] = 0;
25}
26