tests: make no-optimize attribute Clang compatible

This commit is contained in:
Daniel Micay 2020-06-17 16:39:50 -04:00
parent b404d6da6e
commit de3fb50dcc
34 changed files with 113 additions and 67 deletions

View File

@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) #include "test_util.h"
int main(void) {
OPTNONE int main(void) {
void *p = NULL; void *p = NULL;
size_t size = 256 * 1024; size_t size = 256 * 1024;

View File

@ -1,7 +1,10 @@
#include <stdio.h>
#include <malloc.h> #include <malloc.h>
__attribute__((optimize(0))) #include "test_util.h"
int main(void) {
OPTNONE int main(void) {
malloc(1024 * 1024 * 1024); malloc(1024 * 1024 * 1024);
malloc(16); malloc(16);
malloc(32); malloc(32);

View File

@ -1,16 +1,18 @@
#include <pthread.h> #include <pthread.h>
#include <stdio.h>
#include <malloc.h> #include <malloc.h>
__attribute__((optimize(0))) #include "test_util.h"
void leak_memory(void) {
OPTNONE static void leak_memory(void) {
(void)malloc(1024 * 1024 * 1024); (void)malloc(1024 * 1024 * 1024);
(void)malloc(16); (void)malloc(16);
(void)malloc(32); (void)malloc(32);
(void)malloc(4096); (void)malloc(4096);
} }
void *do_work(void *p) { static void *do_work(void *p) {
leak_memory(); leak_memory();
return NULL; return NULL;
} }

View File

@ -1,11 +1,12 @@
#include <stdint.h> #include <stdint.h>
#include "../test_util.h"
struct foo { struct foo {
uint64_t a, b, c, d; uint64_t a, b, c, d;
}; };
__attribute__((optimize(0))) OPTNONE int main(void) {
int main(void) {
void *p = new char; void *p = new char;
struct foo *c = (struct foo *)p; struct foo *c = (struct foo *)p;
delete c; delete c;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
void *p = malloc(128 * 1024); void *p = malloc(128 * 1024);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
void *p = malloc(128 * 1024); void *p = malloc(128 * 1024);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
void *p = malloc(16); void *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
void *p = malloc(16); void *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(8); char *p = malloc(8);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -2,8 +2,9 @@
#include <sys/mman.h> #include <sys/mman.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
free(malloc(16)); free(malloc(16));
char *p = mmap(NULL, 4096 * 16, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); char *p = mmap(NULL, 4096 * 16, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) { if (p == MAP_FAILED) {

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -2,8 +2,9 @@
#include <sys/mman.h> #include <sys/mman.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
free(malloc(16)); free(malloc(16));
char *p = mmap(NULL, 4096 * 16, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); char *p = mmap(NULL, 4096 * 16, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) { if (p == MAP_FAILED) {

View File

@ -1,7 +1,8 @@
#include <malloc.h> #include <malloc.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <malloc.h> #include <malloc.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
void *p = malloc(16); void *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,10 +1,11 @@
#include <stdbool.h> #include <stdbool.h>
#include <malloc.h> #include <malloc.h>
#include "../test_util.h"
size_t malloc_object_size(void *ptr); size_t malloc_object_size(void *ptr);
__attribute__((optimize(0))) OPTNONE int main(void) {
int main(void) {
char *p = malloc(16); char *p = malloc(16);
size_t size = malloc_object_size(p); size_t size = malloc_object_size(p);
return size != (SLAB_CANARY ? 24 : 32); return size != (SLAB_CANARY ? 24 : 32);

View File

@ -1,10 +1,11 @@
#include <stdbool.h> #include <stdbool.h>
#include <malloc.h> #include <malloc.h>
#include "../test_util.h"
size_t malloc_object_size(void *ptr); size_t malloc_object_size(void *ptr);
__attribute__((optimize(0))) OPTNONE int main(void) {
int main(void) {
char *p = malloc(16); char *p = malloc(16);
size_t size = malloc_object_size(p + 5); size_t size = malloc_object_size(p + 5);
return size != (SLAB_CANARY ? 19 : 27); return size != (SLAB_CANARY ? 19 : 27);

View File

@ -2,8 +2,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(128 * 1024); char *p = malloc(128 * 1024);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -2,8 +2,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(0); char *p = malloc(0);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -4,8 +4,9 @@
#include <malloc.h> #include <malloc.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(128 * 1024); char *p = malloc(128 * 1024);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <malloc.h> #include <malloc.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
free((void *)1); free((void *)1);
return 0; return 0;
} }

View File

@ -1,7 +1,8 @@
#include <malloc.h> #include <malloc.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
malloc_usable_size((void *)1); malloc_usable_size((void *)1);
return 0; return 0;
} }

View File

@ -1,7 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
void *p = realloc((void *)1, 16); void *p = realloc((void *)1, 16);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(128 * 1024); char *p = malloc(128 * 1024);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(128 * 1024); char *p = malloc(128 * 1024);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(128); char *p = malloc(128);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(128); char *p = malloc(128);
if (!p) { if (!p) {
return 1; return 1;

View File

@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
__attribute__((optimize(0))) #include "../test_util.h"
int main(void) {
OPTNONE int main(void) {
char *p = malloc(0); char *p = malloc(0);
if (!p) { if (!p) {
return 1; return 1;

10
test/test_util.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef TEST_UTIL_H
#define TEST_UTIL_H
#ifdef __clang__
#define OPTNONE __attribute__((optnone))
#else
#define OPTNONE __attribute__((optimize(0)))
#endif
#endif