tests: make no-optimize attribute Clang compatible

pull/111/head
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 <string.h>
__attribute__((optimize(0)))
int main(void) {
#include "test_util.h"
OPTNONE int main(void) {
void *p = NULL;
size_t size = 256 * 1024;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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