Strengthen against Clang optimizations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
b0f0a64de0
commit
69e8db0366
1 changed files with 15 additions and 9 deletions
|
@ -11,12 +11,21 @@
|
||||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||||
|
|
||||||
#include <mbedtls/platform.h>
|
#include <mbedtls/platform.h>
|
||||||
|
#include <mbedtls/platform_util.h>
|
||||||
#include "test/helpers.h"
|
#include "test/helpers.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* This is an external variable, so the compiler doesn't know that we're never
|
||||||
|
* changing its value.
|
||||||
|
*
|
||||||
|
* TODO: LTO (link-time-optimization) would defeat this.
|
||||||
|
*/
|
||||||
|
int false_but_the_compiler_does_not_know = 0;
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
/* Test framework features */
|
/* Test framework features */
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -35,19 +44,17 @@ void meta_test_fail(const char *name)
|
||||||
void null_pointer_dereference(const char *name)
|
void null_pointer_dereference(const char *name)
|
||||||
{
|
{
|
||||||
(void) name;
|
(void) name;
|
||||||
char *p;
|
volatile char *p;
|
||||||
memset(&p, 0, sizeof(p));
|
mbedtls_platform_zeroize(&p, sizeof(p));
|
||||||
volatile char c;
|
mbedtls_printf("%p -> %u\n", p, (unsigned) *p);
|
||||||
c = *p;
|
|
||||||
(void) c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void null_pointer_call(const char *name)
|
void null_pointer_call(const char *name)
|
||||||
{
|
{
|
||||||
(void) name;
|
(void) name;
|
||||||
void (*p)(void);
|
unsigned (*p)(void);
|
||||||
memset(&p, 0, sizeof(p));
|
mbedtls_platform_zeroize(&p, sizeof(p));
|
||||||
p();
|
mbedtls_printf("%p() -> %u\n", p, p());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +84,6 @@ void read_uninitialized_stack(const char *name)
|
||||||
{
|
{
|
||||||
(void) name;
|
(void) name;
|
||||||
volatile char buf[1];
|
volatile char buf[1];
|
||||||
static int false_but_the_compiler_does_not_know = 0;
|
|
||||||
if (false_but_the_compiler_does_not_know) {
|
if (false_but_the_compiler_does_not_know) {
|
||||||
buf[0] = '!';
|
buf[0] = '!';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue