From 60fc6d2897d628f24d0a4e3e95ab6f5dfe3f8b49 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 4 Nov 2014 18:25:32 -0500 Subject: [PATCH] New API strictaliasing() with GCC support --- src/_premake_init.lua | 12 ++++++++++++ src/tools/gcc.lua | 6 ++++++ tests/tools/test_gcc.lua | 29 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 11aadb3c..ed969b9c 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -630,6 +630,18 @@ tokens = true, } + api.register { + name = "strictaliasing", + scope = "config", + kind = "string", + allowed = { + "Off", + "Level1", + "Level2", + "Level3", + } + } + api.register { name = "system", scope = "config", diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 00c63ddd..1c4865aa 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -51,6 +51,12 @@ if cfg.system ~= premake.WINDOWS then return "-fPIC" end end, }, + strictaliasing = { + Off = "-fno-strict-aliasing", + Level1 = { "-fstrict-aliasing", "-Wstrict-aliasing=1" }, + Level2 = { "-fstrict-aliasing", "-Wstrict-aliasing=2" }, + Level3 = { "-fstrict-aliasing", "-Wstrict-aliasing=3" }, + }, optimize = { Off = "-O0", On = "-O2", diff --git a/tests/tools/test_gcc.lua b/tests/tools/test_gcc.lua index ec2e78af..57c0d06d 100644 --- a/tests/tools/test_gcc.lua +++ b/tests/tools/test_gcc.lua @@ -402,3 +402,32 @@ test.isequal({ '-I"$(IntDir)/includes"' }, gcc.getincludedirs(cfg, cfg.includedirs)) end + + +-- +-- Check handling of strict aliasing flags. +-- + + function suite.cflags_onNoStrictAliasing() + strictaliasing "Off" + prepare() + test.contains("-fno-strict-aliasing", gcc.getcflags(cfg)) + end + + function suite.cflags_onLevel1Aliasing() + strictaliasing "Level1" + prepare() + test.contains({ "-fstrict-aliasing", "-Wstrict-aliasing=1" }, gcc.getcflags(cfg)) + end + + function suite.cflags_onLevel2Aliasing() + strictaliasing "Level2" + prepare() + test.contains({ "-fstrict-aliasing", "-Wstrict-aliasing=2" }, gcc.getcflags(cfg)) + end + + function suite.cflags_onLevel3Aliasing() + strictaliasing "Level3" + prepare() + test.contains({ "-fstrict-aliasing", "-Wstrict-aliasing=3" }, gcc.getcflags(cfg)) + end