Skip to content

GDScript: Suppress -Wdangling-pointer warning for Linux Arm64 release templates - #122789

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
Rafael-Petry:gdscript/suppress-dangling-pointer
Sep 24, 2026
Merged

Repiteo merged 1 commit into
godotengine:masterfrom
Rafael-Petry:gdscript/suppress-dangling-pointer

Conversation

@Rafael-Petry

Copy link
Copy Markdown
Contributor

What problem(s) does this PR solve?

Additional information

It changes the declaration of the call_level variable to be inside the enter_function method, using the memnew function (it is freed on the exit_function method, using memdelete). It also changes the enter_function's signature, as the call_level pointer is not passed as a parameter anymore.

No AI assistance was used on this PR.

This is also my first PR, so any considerations are very much welcome :)

Tests

  • Ran scons target=template_release werror=yes and it finished compiling
  • Ran a simple recursion script to make sure no stack underflow/overflow bugs or memory leaks were introduced

@Rafael-Petry
Rafael-Petry requested a review from a team as a code owner August 25, 2026 01:08
@Repiteo Repiteo added this to the 4.x milestone Aug 25, 2026
@HolonProduction

Copy link
Copy Markdown
Member

What I meant by suppressing in my comment on the issue was actually just applying one of our warning suppression macros e.g. GODOT_GCC_WARNING_IGNORE.

Warnings are meant to help us, but if they do get in the way there is no need to jump through hoops for them. In this case I see no reason to switching to a dedicated heap allocation. The VM code ensures that the lifetime of this pointer does not exceed the lifetime of the stack allocated call level, it's just a bit too complicated for the compiler to recognize.

There might be a point against relying on such complicated contracts, but for the GDScript VM I think it's worth it.

@Rafael-Petry
Rafael-Petry force-pushed the gdscript/suppress-dangling-pointer branch from 8b66154 to 0832058 Compare August 25, 2026 23:16
@Rafael-Petry

Copy link
Copy Markdown
Contributor Author

I must've missed the existence of these macros while looking through the codebase, this is definitely a more reasonable approach.

Just fixed my changes accordingly. Thanks for the tip!

@NoctemCat

NoctemCat commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Maybe runners use older GCC, so that's why it errors? Not fully sure. The error from CI checks:

 ./core/typedefs.h:310:37: error: unknown option after '#pragma GCC diagnostic' kind [-Werror=pragmas]

I think you can try to see if

	GDScriptLanguage::CallLevel call_level;
	GDScriptLanguage::CallLevel* call_level_ptr = &call_level; // Suppress -Wdangling-pointer GCC warning.
	GDScriptLanguage::get_singleton()->enter_function(call_level_ptr, p_instance, this, stack, &ip, &line);

will also suppress it.

@Rafael-Petry

Copy link
Copy Markdown
Contributor Author

I tested your idea and it didn't work unfortunately, it raised the initial dangling pointer warning.

You were correct on the version mismatch of the runner though. The build-linux job runs on ubuntu-22.04, which uses gcc-11 by default. The -Wdangling-pointer warning was introduced on gcc-12 (as stated on the GCC Warning History wiki), which explains why the runner fails to recognize it. I also confirmed this is true by compiling on the different versions locally.

Therefore, I think the way to go would be to just check if the GCC version >= 12 before using the suppressing macros, such as:

#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12
		GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wdangling-pointer") // The VM ensures call_level is not freed while it is in use, so this warning is a false positive for GCC 12+.
#endif

		_call_stack = call_level;

#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12
		GODOT_GCC_WARNING_POP
#endif

If that is a good approach, for what I could see, it both fixes the warning issue when compiling with more recent versions of GCC and also doesn't break compilation for older versions.

Thanks!

@Rafael-Petry
Rafael-Petry force-pushed the gdscript/suppress-dangling-pointer branch from 0832058 to 292efb2 Compare August 26, 2026 23:15

@HolonProduction HolonProduction left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to me beside the comment nitpick 👍

Not exactly an expert on this whole gcc macro stuff, but it seems sane to me and passes CI, so it should be fine.

Comment thread modules/gdscript/gdscript.h Outdated
@HolonProduction HolonProduction modified the milestones: 4.x, 4.8 Sep 23, 2026
@Rafael-Petry
Rafael-Petry force-pushed the gdscript/suppress-dangling-pointer branch from 015b12c to e73c1eb Compare September 23, 2026 20:31
@Rafael-Petry
Rafael-Petry force-pushed the gdscript/suppress-dangling-pointer branch from e73c1eb to 1331b9b Compare September 23, 2026 20:38
@Repiteo
Repiteo merged commit 03e47ae into godotengine:master Sep 24, 2026
20 checks passed
@Repiteo

Repiteo commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Thanks! Congratulations on your first merged contribution! 🎉

@Rafael-Petry
Rafael-Petry deleted the gdscript/suppress-dangling-pointer branch September 24, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The GDScript module raises a -Wdangling-pointer warning for Linux Arm64 release templates

4 participants