Bug 48026 - #pragma optimize ignored for C++ for preprocessor
Summary: #pragma optimize ignored for C++ for preprocessor
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 114370 (view as bug list)
Depends on: 41201
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-07 19:44 UTC by Sam Morris
Modified: 2024-03-18 00:32 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-11-20 00:00:00


Attachments
Proposed patch against trunk (1.72 KB, patch)
2023-12-06 08:31 UTC, Gwenole Beauchesne
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Morris 2011-03-07 19:44:07 UTC
#pragma optimize seems to be ignored for C++.


=== Makefile ===
all: opt_c.s opt_cxx.s
.PHONY: all

opt_c.s: opt.c
	gcc -S -o $@ -O2 $<

opt_cxx.s: opt.c
	g++ -S -o $@ -O2 $<

clean:
	rm -f *.s
.PHONY: clean

=== opt.c ===
#pragma GCC optimize ("O0")

#ifdef __OPTIMIZE__
#error help!
#endif

int main () {
	int i;
	for (i = 0; i < 2000000000; ++i)
		;
}

=== test output ===
$ make -k
gcc -S -o opt_c.s -O2 opt.c
g++ -S -o opt_cxx.s -O2 opt.c
opt.c:4:2: error: #error help!
make: *** [opt_cxx.s] Error 1
make: Target `all' not remade because of errors.
Comment 1 Andrew Pinski 2012-02-02 06:24:46 UTC
Confirmed, this is most likely the same issue as PR 41201.
Comment 2 Allan Jensen 2012-07-25 12:40:22 UTC
(In reply to comment #1)
> Confirmed, this is most likely the same issue as PR 41201.

Well, not completely the same. The original issue reported in PR 41201 is about defining the macros, but the possible fix in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41201#c6 is about this bug.
Comment 3 Frank 2014-12-10 17:33:43 UTC
Still existent in 4.8.4
Comment 4 Manuel López-Ibáñez 2014-12-17 12:56:43 UTC
This is probably because the preprocessor runs before the #pragmas are handled. If so, this is the same issue as for #pragma GCC diagnostics in C++ (PR53431).
Comment 5 Gwenole Beauchesne 2023-12-06 08:31:47 UTC
Created attachment 56811 [details]
Proposed patch against trunk

Here is a proposed patch against trunk, which includes a fix for PR preprocessor/87299 (#pragma GCC target).
Comment 6 Sam James 2023-12-06 08:35:16 UTC
(In reply to Gwenole Beauchesne from comment #5)
> Created attachment 56811 [details]
> Proposed patch against trunk
> 
> Here is a proposed patch against trunk, which includes a fix for PR
> preprocessor/87299 (#pragma GCC target).

Could you send this to the mailing list if it's still relevant? Thanks.

(https://gcc.gnu.org/contribute.html)
Comment 7 Andrew Pinski 2024-03-18 00:32:41 UTC
*** Bug 114370 has been marked as a duplicate of this bug. ***