Commit f3d52124 authored by Matthias Braun's avatar Matthias Braun
Browse files

reorganize noreturn,printf,nothrow attributes in funcattr.h

parent 88b246dc
/*
* This file is part of libFirm.
* Copyright (C) 2014 Karlsruhe Institute of Technology
*/
/**
* @file
* @brief Macros for declaring extra function attributes
* @author Matthias Braun
*/
#ifndef FIRM_FUNCATTR_H
#define FIRM_FUNCATTR_H
/**
* @def FIRM_NOTHROW
* Tells that a function does not throw C++ exceptions. Currently this is only
* necessary for obstack_printf to avoid nameclashes when linking with glibc
* which has an obstack library with NOTHROW builtin.
*/
#ifdef __cplusplus
# define FIRM_NOTHROW throw ()
#else
# define FIRM_NOTHROW
#endif
/**
* @def FIRM_PRINTF
* Attribute to mark a function to have a printf style format string and
* variadic arguments.
*/
#ifdef __GNUC__
# define FIRM_PRINTF(a,b) __attribute__((__format__(__printf__, a, b)))
#else
# define FIRM_PRINTF(a,b)
#endif
/**
* @def FIRM_NORETURN
* Attribute to mark a function which never returns.
*/
#if defined(__STDC__) && (__STDC_VERSION__ >= 201112L)
# define FIRM_NORETURN _Noreturn void
#elif defined(__GNUC__)
# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 70)
# define FIRM_NORETURN __attribute__((__noreturn__)) void
# endif
#elif defined(_MSC_VER)
# define FIRM_NORETURN void __declspec(noreturn)
#else
# define FIRM_NORETURN void
#endif
#endif
......@@ -154,6 +154,8 @@ Summary:
#include <string.h>
#include <stdarg.h>
#include "funcattr.h"
struct _obstack_chunk /* Lives at front of each chunk. */
{
char *limit; /* 1 past end of this chunk */
......@@ -206,7 +208,7 @@ FIRM_API void obstack_free (struct obstack *obstack, void *block);
more memory. This can be set to a user defined function which
should either abort gracefully or use longjump - but shouldn't
return. The default action is to print a message and abort. */
FIRM_API void (*obstack_alloc_failed_handler) (void);
FIRM_API FIRM_NORETURN (*obstack_alloc_failed_handler) (void);
/* Exit value used when `print_and_abort' is used. */
FIRM_API int obstack_exit_failure;
......@@ -514,27 +516,6 @@ __extension__ \
#endif /* not __GNUC__ or not __STDC__ */
/** @def FIRM_NOTHROW
* tells that a function does not throw C++ exceptions. Currently this is only
* necessary for obstack_printf to avoid nameclashes when linking with glibc
* which has an obstack library with NOTHROW builtin. */
#ifdef __cplusplus
# define FIRM_NOTHROW throw ()
#else
# define FIRM_NOTHROW
#endif
/**
* @def FIRM_PRINTF
* Attribute with marks a function to have a printf style format
* string and variadic argument.
*/
#if defined(__GNUC__)
# define FIRM_PRINTF(a,b) __attribute__((__format__(__printf__, a, b)))
#else
# define FIRM_PRINTF(a,b)
#endif
/** prints formated string (printf-style format) to an obstack.
* This is done by "growing" the obstack with the obstack_*grow*
* functions. Note: Does NOT append a null-byte. */
......
......@@ -12,10 +12,10 @@
#include <stdio.h>
#include <stdlib.h>
#include "funcattr.h"
#include "xmalloc.h"
#include "error.h"
static NORETURN xnomem(void)
static FIRM_NORETURN xnomem(void)
{
/* Do not use panic() here, because it might try to allocate memory! */
fputs("out of memory", stderr);
......
......@@ -15,7 +15,8 @@
#include "error.h"
#include "irprintf.h"
NORETURN (panic)(char const *const file, int const line, char const *const func, char const *const fmt, ...)
FIRM_NORETURN (panic)(char const *const file, int const line,
char const *const func, char const *const fmt, ...)
{
va_list ap;
......
......@@ -11,36 +11,13 @@
#ifndef FIRM_COMMON_ERROR_H
#define FIRM_COMMON_ERROR_H
/**
* @file
*
* Error handling for libFirm.
*
* @author Michael Beck
*/
/* define a NORETURN attribute */
#ifndef NORETURN
# if defined(__GNUC__)
# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 70)
# define NORETURN void __attribute__ ((noreturn))
# endif /* __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 70) */
# endif /* defined(__GNUC__) */
# if defined(_MSC_VER)
# define NORETURN void __declspec(noreturn)
# endif /* defined(_MSC_VER) */
/* If not set above, use "void" for DOES_NOT_RETURN. */
# ifndef NORETURN
# define NORETURN void
# endif /* ifndef NORETURN */
#endif /* ifndef NORETURN */
#include "funcattr.h"
/**
* Prints a panic message to stderr and exits.
*/
NORETURN panic(char const *file, int line, char const *func, char const *fmt, ...);
FIRM_NORETURN panic(char const *file, int line, char const *func,
char const *fmt, ...);
#define panic(...) panic(__FILE__, __LINE__, __func__, __VA_ARGS__)
......
......@@ -146,7 +146,7 @@ static int id_cmp(const void *elt, const void *key, size_t size)
return entry->id - keyentry->id;
}
static void __attribute__((format(printf, 2, 3)))
static void FIRM_PRINTF(2, 3)
parse_error(read_env_t *env, const char *fmt, ...)
{
/* workaround read_c "feature" that a '\n' triggers the line++
......
......@@ -64,8 +64,8 @@ enum
abort gracefully or use longjump - but shouldn't return. This
variable by default points to the internal function
`print_and_abort'. */
static void print_and_abort (void);
void (*obstack_alloc_failed_handler) (void) = print_and_abort;
static FIRM_NORETURN print_and_abort (void);
FIRM_NORETURN (*obstack_alloc_failed_handler) (void) = print_and_abort;
/* Exit value used when `print_and_abort' is used. */
# include <stdlib.h>
......@@ -331,7 +331,7 @@ PTR_INT_TYPE _obstack_memory_used(struct obstack *h)
return nbytes;
}
static void __attribute__((noreturn)) print_and_abort(void)
static FIRM_NORETURN print_and_abort(void)
{
/* Don't change any of these strings. Yes, it would be possible to add
the newline to the string and use fputs or so. But this must not
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment