[LTP] [PATCH v2] hugepage15: Resolve compile time warning generating with -O0

Tarun Sahu
2023-02-13T15:27:45Z

Instead of turning off the optimizaton with -O0 to resolve unwanted
behaviour of clang with goto statements, this will make use of clang
pragma to turn off the optimization for just clang compiler. This way,
gcc won't throw unwanted warning on turning off optimization:
"warning: _FORTIFY_SOURCE requires compiling with optimization (-O)".

Also, removed redundant header-includes.

Reported-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
v2:
- rebase and added Reviewed-by

testcases/kernel/mem/hugetlb/hugemmap/Makefile | 1 -
testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c | 13 ++++---------
2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/Makefile b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
index 6f10807cd..2d651b4aa 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
@@ -8,5 +8,4 @@ include $(top_srcdir)/include/mk/testcases.mk
include $(abs_srcdir)/../Makefile.inc
include $(top_srcdir)/include/mk/generic_leaf_target.mk

-hugemmap15: CFLAGS+=-O0
hugemmap06: CFLAGS+=-pthread
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
index 07e65a160..4d1984070 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
@@ -19,6 +19,10 @@
* remap, or because the icache happens to get flushed in the interim.
*/

+#if defined(__clang__)
+ #pragma clang optimize off
+#endif
+
#define _GNU_SOURCE
#include "hugetlb.h"

@@ -27,16 +31,7 @@
defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) || \
defined(__i386__) || defined(__x86_64__) || defined(__arm__)

-#include <stdio.h>
-#include <stdlib.h>
#include <setjmp.h>
-#include <unistd.h>
-#include <signal.h>
-#include <sys/mman.h>
-#include <ucontext.h>
-#include <limits.h>
-#include <sys/param.h>
-#include <sys/types.h>

#define SUCC_JMP 1
#define FAIL_JMP 2
--
2.31.1