Skip to content

Commit 2ca53fd

Browse files
committed
add gcc patch for gcc 13
1 parent 211bcd2 commit 2ca53fd

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+

gcc/overlay.nix

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
self: super: let
1+
self: super: with super; let
22
pname = "luogu-gcc";
33

4-
applyLuogu = gcc: let
4+
applyLuogu = gcc: additionalPatches: wrapCCWith {
55
cc = gcc.cc.overrideAttrs(a: with a; {
66
inherit pname;
7-
patches = patches ++ [
8-
./disable-pragma-and-attribute-for-optimize.patch
9-
];
7+
patches = patches ++ additionalPatches;
108
});
11-
in super.wrapCC(cc);
9+
};
1210
in {
13-
luogu-gcc = applyLuogu(super.gcc13);
14-
luogu-gcc930 = applyLuogu(super.gcc930);
11+
luogu-gcc = applyLuogu gcc13 [
12+
./13_disable-pragma-and-attribute-for-optimize.patch
13+
];
14+
luogu-gcc930 = applyLuogu gcc930 [
15+
./9_disable-pragma-and-attribute-for-optimize.patch
16+
];
1517
}

0 commit comments

Comments
 (0)