|
| 1 | +From 83da2924c87eabd50a13da7b9868939defd4efbb Mon Sep 17 00:00:00 2001 |
| 2 | +From: Soha Jin < [email protected]> |
| 3 | +Date: Sun, 12 Nov 2023 17:05:55 +0800 |
| 4 | +Subject: [PATCH] disable optimize pragmas and attributes in ONLINE_JUDGE environment |
| 5 | + |
| 6 | +--- |
| 7 | + gcc/c-family/c-attribs.cc | 6 ++++++ |
| 8 | + gcc/c-family/c-pragma.cc | 6 ++++++ |
| 9 | + 2 files changed, 12 insertions(+) |
| 10 | + |
| 11 | +diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc |
| 12 | +index 072cfb691..0c1a26b21 100644 |
| 13 | +--- a/gcc/c-family/c-attribs.cc |
| 14 | ++++ b/gcc/c-family/c-attribs.cc |
| 15 | +@@ -5626,6 +5626,12 @@ static tree |
| 16 | + handle_optimize_attribute (tree *node, tree name, tree args, |
| 17 | + int ARG_UNUSED (flags), bool *no_add_attrs) |
| 18 | + { |
| 19 | ++ if (getenv("ONLINE_JUDGE")) |
| 20 | ++ { |
| 21 | ++ error_at (DECL_SOURCE_LOCATION (*node), "%qE attribute is disallowed in online judge mode", name); |
| 22 | ++ return NULL_TREE; |
| 23 | ++ } |
| 24 | ++ |
| 25 | + /* Ensure we have a function type. */ |
| 26 | + if (TREE_CODE (*node) != FUNCTION_DECL) |
| 27 | + { |
| 28 | +diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc |
| 29 | +index 0d2b333ce..091c0edc9 100644 |
| 30 | +--- a/gcc/c-family/c-pragma.cc |
| 31 | ++++ b/gcc/c-family/c-pragma.cc |
| 32 | +@@ -1163,6 +1163,12 @@ handle_pragma_optimize (cpp_reader *) |
| 33 | + bool close_paren_needed_p = false; |
| 34 | + tree optimization_previous_node = optimization_current_node; |
| 35 | + |
| 36 | ++ if (getenv("ONLINE_JUDGE")) |
| 37 | ++ { |
| 38 | ++ error ("%<#pragma GCC optimize%> is not allowed in online judge mode"); |
| 39 | ++ return; |
| 40 | ++ } |
| 41 | ++ |
| 42 | + if (cfun) |
| 43 | + { |
| 44 | + error ("%<#pragma GCC optimize%> is not allowed inside functions"); |
| 45 | +-- |
| 46 | +2.39.2 |
| 47 | + |
0 commit comments