Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some additional changes I needed for gcc to build the source #17655

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

slapin
Copy link

@slapin slapin commented Mar 27, 2024

What does this PR do?

This PR adds changes which are required to produce engine/project build using gcc.
I tested using gcc-11.

Please describe your PR. For a bug fix, what was the old behavior, what is the new behavior?
Lots of various kinds of errors regarding c++ stuff.

Please add links to any issues, RFCs or other items that are relevant to this PR.

How was this PR tested?

Just built on my host ubuntu 22.04 system.

Please describe any testing performed.
Just built and run Editor.

Today, on March, 31 I tried building Paper Kid demo and it works perfectly fine, with editor and game itself,
I used AssetProcessorBatch to pre-process assets.

@slapin slapin requested review from a team as code owners March 27, 2024 12:13
@slapin
Copy link
Author

slapin commented Mar 27, 2024

Currently it is more a subject for discussion I guess, so I'd like to collect some feedback.

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch 2 times, most recently from bd003a3 to c19d7cd Compare March 29, 2024 10:05
@AMZN-daimini
Copy link
Contributor

Started AR, but awaiting response from @o3de/sig-build before reviewing.

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from c19d7cd to 8247f1a Compare March 29, 2024 10:58
@@ -2015,7 +2015,9 @@ namespace AZ
}
else
{
AZ_PUSH_DISABLE_WARNING_GCC(-Wdangling-pointer);
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement looks wrong, it should be

Suggested change
AZ_PUSH_DISABLE_WARNING_GCC(-Wdangling-pointer);
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");

This will produce an error like:

missing option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]

is that why there is an additional -Wno-error=pragmas below?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, fixed that.

@@ -73,6 +74,15 @@ ly_append_configurations_options(
-Wno-switch
-Wno-uninitialized
-Wno-unused-result
-Wno-dangling-pointer
Copy link
Author

Choose a reason for hiding this comment

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

In file included from /media/slapin/data/o3de-projects/NewspaperDeliveryGame/build/linux/o3de/Code/Framework/AzCore/CMakeFiles/AzCore.dir/Unity/unity_15_cxx.cxx:15:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp: In function ‘AZ::Metrics::Script::ReflectRecordEvent(AZ::BehaviorContext&)::<lambda(AZ::Metrics::EventLoggerId, AZ::Metrics::EventPhaseNamespace::EventPhase, AZ::Metrics::Script::ScriptEventArgs, AZ::Metrics::IEventLoggerFactory*)>’:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp:465:66: note: unnamed temporary defined here
  465 |                     asyncArgs.m_id = eventPhaseArgs.m_id.value_or(AZStd::string_view{});
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

No, that is still needed

-Wno-error=unused-but-set-variable
-Wno-error=unused-variable
-Wno-error=subobject-linkage
-Wno-error=pragmas
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldnt be needed with that warning disable statement above

Copy link
Author

Choose a reason for hiding this comment

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

Removed -Wno-error=pragmas

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from 8247f1a to 865aaab Compare March 29, 2024 23:17
@slapin
Copy link
Author

slapin commented Mar 30, 2024

Please explain Jenkins errors, these do not look like related...

@spham-amzn
Copy link
Contributor

Please explain Jenkins errors, these do not look like related...

It looks like the pdb files were corrupted. I've seen this happen in a couple of recent builds, so the corruption is mostl likely caused by the intermediate artifacts that gets cached and pushed to other intermediate builds. You can restart the build with a rebuild all, but that cache will need to be cleaned up either way.

@slapin
Copy link
Author

slapin commented Mar 30, 2024

Ah, thanks, so these are beyond what I can do and not related to the changes.

@slapin
Copy link
Author

slapin commented Mar 31, 2024

With this PR and build with gcc-13 using script

#!/bin/sh
set -e
set -x
cd ../o3de
git stash
git pull --rebase
stash_count=$(git stash list|wc -l)
if [ $stash_count -gt 0 ]; then
        git stash pop
fi
cmake -B build/linux -S . -G "Ninja Multi-Config" -DCMAKE_C_COMPILER=gcc-13 -DCMAKE_CXX_COMPILER=g++-13

cd ../o3de-projects
cd NewspaperDeliveryGame
git clean -d -f -x
cmake -B build/linux -S . -G "Ninja Multi-Config" -DCMAKE_C_COMPILER=gcc-13 -DCMAKE_CXX_COMPILER=g++-13
cmake --build build/linux --target Paper_Kid.GameLauncher Editor AssetProcessorBatch AssetBundlerBatch --config profile -j16

I confirm Paper Kid game builds and run with Editor working. I run AssetProcessorBatch as AssetProcessor is annoying af, otherwise everything seems to be working.

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from 865aaab to a913104 Compare April 3, 2024 08:20
@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from a913104 to 18f1a08 Compare April 12, 2024 13:48
Comment on lines 81 to 83
-Wno-error=return-local-addr
-Wno-error=nonnull
-Wno-error=free-nonheap-object
-Wno-error=use-after-free
Copy link
Contributor

Choose a reason for hiding this comment

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

These warnings actually are important and useful.

Returning a pointer to a local address or using a variable after free shouldn't be ignored, but the code in question should be fixed.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure I can handle the volume, but I will try

Copy link
Author

Choose a reason for hiding this comment

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

/media/slapin/data/o3de/Code/Editor/Util/ImageTIF.cpp: In static member function ‘static const char* CImageTIF::GetPreset(const QString&)’:
/media/slapin/data/o3de/Code/Editor/Util/ImageTIF.cpp:498:1: error: function may return address of local variable [-Werror=return-local-addr]
  498 | }
      | ^
/media/slapin/data/o3de/Code/Editor/Util/ImageTIF.cpp:475:19: note: declared here
  475 |     AZStd::string strReturn;
      |                   ^~~~~~~~~

The function returns c_str() from local string

Copy link
Contributor

Choose a reason for hiding this comment

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

That doesn't look good :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

That is actually a legitimate bug that shouldn't be suppressed.

It looks like there isn't any code which calls the GetPreset function which returns a local const char*.
Therefore we can just delete the entire function itself to fix the issue.

Copy link
Author

Choose a reason for hiding this comment

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

Lots of stuff like

In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘constexpr ForwardIterator AZStd::Internal::uninitialized_move(InputIterator, InputIterator, ForwardIterator, bool) [with InputIterator = AZ::Component**; ForwardIterator = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:526:29,
    inlined from ‘ForwardIt AZStd::uninitialized_move(InputIt, InputIt, ForwardIt) [with InputIt = AZ::Component**; ForwardIt = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:555:51,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_iter(const_iterator, Iterator, Iterator) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1125:56,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_impl(const_iterator, const Iterator&, const Iterator&, const std::false_type&) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1067:31,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert(const_iterator, InputIterator, InputIterator) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:787:31,
    inlined from ‘void AZStd::vector<T, Allocator>::assign_iter(const InputIterator&, const InputIterator&, const std::false_type&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1245:19,
    inlined from ‘void AZStd::vector<T, Allocator>::assign(const InputIterator&, const InputIterator&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:595:24,
    inlined from ‘static std::unique_ptr<QMimeData> AzToolsFramework::ComponentMimeData::Create(AZStd::span<AZ::Component* const>)’ at /media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/ComponentMimeData.cpp:129:46:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: error: argument 2 null where non-null expected [-Werror=nonnull]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: note: in a call to built-in function ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’
In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘constexpr ForwardIterator AZStd::Internal::uninitialized_move(InputIterator, InputIterator, ForwardIterator, bool) [with InputIterator = AZ::Component**; ForwardIterator = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:526:29,
    inlined from ‘ForwardIt AZStd::uninitialized_move(InputIt, InputIt, ForwardIt) [with InputIt = AZ::Component**; ForwardIt = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:555:51,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_iter(const_iterator, Iterator, Iterator) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1147:64,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_impl(const_iterator, const Iterator&, const Iterator&, const std::false_type&) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1067:31,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert(const_iterator, InputIterator, InputIterator) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:787:31,
    inlined from ‘void AZStd::vector<T, Allocator>::assign_iter(const InputIterator&, const InputIterator&, const std::false_type&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1245:19,
    inlined from ‘void AZStd::vector<T, Allocator>::assign(const InputIterator&, const InputIterator&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:595:24,
    inlined from ‘static std::unique_ptr<QMimeData> AzToolsFramework::ComponentMimeData::Create(AZStd::span<AZ::Component* const>)’ at /media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/ComponentMimeData.cpp:129:46:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: error: argument 2 null where non-null expected [-Werror=nonnull]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: note: in a call to built-in function ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’
In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘constexpr ForwardIterator AZStd::Internal::copy(InputIterator, InputIterator, ForwardIterator, bool) [with InputIterator = AZ::Component* const*; ForwardIterator = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:256:29,
    inlined from ‘constexpr OutputIterator AZStd::copy(InputIterator, InputIterator, OutputIterator) [with InputIterator = AZ::Component* const*; OutputIterator = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:391:30,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_iter(const_iterator, Iterator, Iterator) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1162:32,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_impl(const_iterator, const Iterator&, const Iterator&, const std::false_type&) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1067:31,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert(const_iterator, InputIterator, InputIterator) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:787:31,
    inlined from ‘void AZStd::vector<T, Allocator>::assign_iter(const InputIterator&, const InputIterator&, const std::false_type&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1245:19,
    inlined from ‘void AZStd::vector<T, Allocator>::assign(const InputIterator&, const InputIterator&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:595:24,
    inlined from ‘static std::unique_ptr<QMimeData> AzToolsFramework::ComponentMimeData::Create(AZStd::span<AZ::Component* const>)’ at /media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/ComponentMimeData.cpp:129:46:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: error: argument 1 null where non-null expected [-Werror=nonnull]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: note: in a call to built-in function ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’
In function ‘void* memmove(void*, const void*, size_t)’,
    inlined from ‘constexpr BidirectionalIterator2 AZStd::Internal::move_backward(BidirectionalIterator1, BidirectionalIterator1, BidirectionalIterator2, bool) [with BidirectionalIterator1 = AZ::Component**; BidirectionalIterator2 = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:485:30,
    inlined from ‘BidirectionalIterator2 AZStd::move_backward(BidirectionalIterator1, BidirectionalIterator1, BidirectionalIterator2) [with BidirectionalIterator1 = AZ::Component**; BidirectionalIterator2 = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:567:46,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_iter(const_iterator, Iterator, Iterator) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1177:41,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_impl(const_iterator, const Iterator&, const Iterator&, const std::false_type&) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1067:31,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert(const_iterator, InputIterator, InputIterator) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:787:31,
    inlined from ‘void AZStd::vector<T, Allocator>::assign_iter(const InputIterator&, const InputIterator&, const std::false_type&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1245:19,
    inlined from ‘void AZStd::vector<T, Allocator>::assign(const InputIterator&, const InputIterator&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:595:24,
    inlined from ‘static std::unique_ptr<QMimeData> AzToolsFramework::ComponentMimeData::Create(AZStd::span<AZ::Component* const>)’ at /media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/ComponentMimeData.cpp:129:46:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:36:34: error: argument 2 null where non-null expected [-Werror=nonnull]
   36 |   return __builtin___memmove_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   37 |                                   __glibc_objsize0 (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:36:34: note: in a call to built-in function ‘void* __builtin_memmove(void*, const void*, long unsigned int)’
In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘constexpr ForwardIterator AZStd::Internal::copy(InputIterator, InputIterator, ForwardIterator, bool) [with InputIterator = AZ::Component* const*; ForwardIterator = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:256:29,
    inlined from ‘constexpr OutputIterator AZStd::copy(InputIterator, InputIterator, OutputIterator) [with InputIterator = AZ::Component* const*; OutputIterator = AZ::Component**]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/createdestroy.h:391:30,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_iter(const_iterator, Iterator, Iterator) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1180:32,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert_impl(const_iterator, const Iterator&, const Iterator&, const std::false_type&) [with Iterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1067:31,
    inlined from ‘T* AZStd::vector<T, Allocator>::insert(const_iterator, InputIterator, InputIterator) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:787:31,
    inlined from ‘void AZStd::vector<T, Allocator>::assign_iter(const InputIterator&, const InputIterator&, const std::false_type&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:1245:19,
    inlined from ‘void AZStd::vector<T, Allocator>::assign(const InputIterator&, const InputIterator&) [with InputIterator = AZ::Component* const*; T = AZ::Component*; Allocator = AZStd::allocator]’ at /media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/vector.h:595:24,
    inlined from ‘static std::unique_ptr<QMimeData> AzToolsFramework::ComponentMimeData::Create(AZStd::span<AZ::Component* const>)’ at /media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/ComponentMimeData.cpp:129:46:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: error: argument 1 null where non-null expected [-Werror=nonnull]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~

looks like memcpy() arguments problems.

Copy link
Author

Choose a reason for hiding this comment

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

used static_cast<uint8_t *>(ptr) with std::launder, might work but I'm not sure yet.

Copy link
Author

Choose a reason for hiding this comment

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

fixed another set in AZStd::vector but still lots of stuff in other parts.

Copy link
Author

Choose a reason for hiding this comment

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

Mitigated all -Wnonnull things, hope these will be much better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

@byrcolin byrcolin added sig/build Categorizes an issue or PR as relevant to SIG Build. sig/graphics-audio Categorizes an issue or PR as relevant to SIG graphics-audio. labels Apr 16, 2024
@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from 18f1a08 to 81a7b8e Compare April 16, 2024 17:58
@slapin slapin requested a review from a team as a code owner April 16, 2024 17:58
@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from 81a7b8e to f831b76 Compare April 17, 2024 01:25
@@ -132,7 +132,7 @@ namespace AZ

bool DirectionalLightComponentConfig::IsEsmDisabled() const
{
return !m_shadowEnabled || (m_shadowFilterMethod != ShadowFilterMethod::Esm && m_shadowFilterMethod != ShadowFilterMethod::EsmPcf);
return !m_shadowEnabled || !(m_shadowFilterMethod == ShadowFilterMethod::Esm || m_shadowFilterMethod == ShadowFilterMethod::EsmPcf);
Copy link
Contributor

Choose a reason for hiding this comment

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

good ol' De Morgan

Copy link
Author

Choose a reason for hiding this comment

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

This change is more correct from compiler point of view, need to check which error that was and it was not related to De Morgan per se.

-Wno-error=unused-variable
-Wno-error=subobject-linkage
-Wno-error=nonnull
-Wno-error=free-nonheap-object
Copy link
Contributor

Choose a reason for hiding this comment

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

free non-heap
does this really happen or it's a false positive?

Copy link
Author

Choose a reason for hiding this comment

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

it happens a lot because of templates freeing stuff not being allocated (having various weird offsets and not page aligned) so I guess some weird magic happens in O3DE which -Wfree-nonheap-object do not understand.

Copy link
Author

Choose a reason for hiding this comment

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

about -Wfree-nonheap-object:

In destructor ‘_i_reference_target<Counter>::~_i_reference_target() [with Counter = int]’,
    inlined from ‘void _i_reference_target<Counter>::Release() [with Counter = int]’ at /media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:335:13,
    inlined from ‘_smart_ptr<_I>::~_smart_ptr() [with _I = CUiAnimViewKeyUIControls]’ at /media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:67:23,
    inlined from ‘constexpr void std::_Destroy(_Tp*) [with _Tp = _smart_ptr<CUiAnimViewKeyUIControls>]’ at /usr/include/c++/13/bits/stl_construct.h:151:22,
    inlined from ‘static void std::_Destroy_aux<<anonymous> >::__destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = _smart_ptr<CUiAnimViewKeyUIControls>*; bool <anonymous> = false]’ at /usr/include/c++/13/bits/stl_construct.h:163:19,
    inlined from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = _smart_ptr<CUiAnimViewKeyUIControls>*]’ at /usr/include/c++/13/bits/stl_construct.h:196:11,
    inlined from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, allocator<_T2>&) [with _ForwardIterator = _smart_ptr<CUiAnimViewKeyUIControls>*; _Tp = _smart_ptr<CUiAnimViewKeyUIControls>]’ at /usr/include/c++/13/bits/alloc_traits.h:947:15,
    inlined from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = _smart_ptr<CUiAnimViewKeyUIControls>; _Alloc = std::allocator<_smart_ptr<CUiAnimViewKeyUIControls> >]’ at /usr/include/c++/13/bits/stl_vector.h:732:15,
    inlined from ‘virtual CUiAnimViewKeyPropertiesDlg::~CUiAnimViewKeyPropertiesDlg()’ at /media/slapin/data/o3de/Gems/LyShine/Code/Editor/Animation/UiAnimViewKeyPropertiesDlg.h:147:7,
    inlined from ‘virtual CUiAnimViewKeyPropertiesDlg::~CUiAnimViewKeyPropertiesDlg()’ at /media/slapin/data/o3de/Gems/LyShine/Code/Editor/Animation/UiAnimViewKeyPropertiesDlg.h:147:7:
/media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:324:5: error: ‘void operator delete(void*, std::size_t)’ called on pointer ‘*(CUiAnimViewKeyUIControls**)((char*)__first)’ with nonzero offset 16 [-Werror=free-nonheap-object]
  324 |     }
      |     ^
In destructor ‘_i_reference_target<Counter>::~_i_reference_target() [with Counter = int]’,
    inlined from ‘void _i_reference_target<Counter>::Release() [with Counter = int]’ at /media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:335:13,
    inlined from ‘_smart_ptr<_I>::~_smart_ptr() [with _I = CUiAnimViewKeyUIControls]’ at /media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:67:23,
    inlined from ‘constexpr void std::_Destroy(_Tp*) [with _Tp = _smart_ptr<CUiAnimViewKeyUIControls>]’ at /usr/include/c++/13/bits/stl_construct.h:151:22,
    inlined from ‘static void std::_Destroy_aux<<anonymous> >::__destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = _smart_ptr<CUiAnimViewKeyUIControls>*; bool <anonymous> = false]’ at /usr/include/c++/13/bits/stl_construct.h:163:19,
    inlined from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = _smart_ptr<CUiAnimViewKeyUIControls>*]’ at /usr/include/c++/13/bits/stl_construct.h:196:11,
    inlined from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, allocator<_T2>&) [with _ForwardIterator = _smart_ptr<CUiAnimViewKeyUIControls>*; _Tp = _smart_ptr<CUiAnimViewKeyUIControls>]’ at /usr/include/c++/13/bits/alloc_traits.h:947:15,
    inlined from ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(iterator, _Args&& ...) [with _Args = {_smart_ptr<CUiAnimViewKeyUIControls>}; _Tp = _smart_ptr<CUiAnimViewKeyUIControls>; _Alloc = std::allocator<_smart_ptr<CUiAnimViewKeyUIControls> >]’ at /usr/include/c++/13/bits/vector.tcc:517:15:
/media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:324:5: error: ‘void operator delete(void*, std::size_t)’ called on pointer ‘*(CUiAnimViewKeyUIControls**)((char*)__first)’ with nonzero offset 16 [-Werror=free-nonheap-object]
  324 |     }
      |     ^
In destructor ‘_i_reference_target<Counter>::~_i_reference_target() [with Counter = int]’,
    inlined from ‘void _i_reference_target<Counter>::Release() [with Counter = int]’ at /media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:335:13,
    inlined from ‘_smart_ptr<_I>::~_smart_ptr() [with _I = CUiAnimViewKeyUIControls]’ at /media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:67:23,
    inlined from ‘CUiAnimViewKeyPropertiesDlg::CUiAnimViewKeyPropertiesDlg(QWidget*)’ at /media/slapin/data/o3de/Gems/LyShine/Code/Editor/Animation/UiAnimViewKeyPropertiesDlg.cpp:89:28:
/media/slapin/data/o3de/Code/Legacy/CryCommon/./smartptr.h:324:5: error: ‘void operator delete(void*, std::size_t)’ called on pointer ‘<unknown>’ with nonzero offset 16 [-Werror=free-nonheap-object]
  324 |     }
      |     ^
In file included from /media/slapin/data/o3de-projects/pong/build/linux/External/LyShine-dae488a6/Code/CMakeFiles/LyShine.Tools.Static.dir/Unity/unity_14_cxx.cxx:7:
/media/slapin/data/o3de/Gems/LyShine/Code/Editor/Animation/UiAnimViewKeyPropertiesDlg.cpp: In constructor ‘CUiAnimViewKeyPropertiesDlg::CUiAnimViewKeyPropertiesDlg(QWidget*)’:
/media/slapin/data/o3de/Gems/LyShine/Code/Editor/Animation/UiAnimViewKeyPropertiesDlg.cpp:87:65: note: returned from ‘void* operator new(std::size_t)’
   87 |     CUiAnimViewTrackEventKeyUIControls* trackEventControl = new CUiAnimViewTrackEventKeyUIControls;
      |                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont see how the CUiAnimViewKeyUIControls class needs to be derived from QObject nor inherit QObject in its class. Might be best to remove that and see if the alignment cleans up - all other ref counted _smart_ptr objects are single-inheritors with no offset... ?

one issue is I can't seem to repro these, on clang16 or clang14 with asan / fortify. So I can't experiment with different options to see if it can be fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I tried removing the QObject inherit and Q_OBJECT in its class def from CUiAnimViewKeyUIControls and the track view seems to work just fine and show those key ui controls without issue, I think it was an oversight. Perhaps removing it will clear the issue for you

Copy link
Author

Choose a reason for hiding this comment

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

Cool, indeed it fixed the issue with -Wfree-nonheap-object, Thanks a lot!

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from f831b76 to 3dad6e4 Compare April 19, 2024 18:20
Comment on lines 119 to 121
AZ_PUSH_DISABLE_WARNING_GCC("-Wuse-after-free");
AZ_MEMORY_PROFILE(ProfileReallocation(oldPtr, newPtr, allocatedSize, 1));
AZ_POP_DISABLE_WARNING_GCC;
Copy link
Contributor

@lemonade-dm lemonade-dm Apr 20, 2024

Choose a reason for hiding this comment

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

The warning suppression shouldn't be needed any longer here now that the pointer has been "laundered".

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, fixed.

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch 2 times, most recently from d00ae4b to 9b5e0a8 Compare April 20, 2024 04:27
@slapin
Copy link
Author

slapin commented Apr 20, 2024

About dangling pointers -Wdangling-pointer

/media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/variant_impl.h:410:19: error: dangling pointer to an unnamed temporary may be used [-Werror=dangling-pointer=]
  410 |                 : m_value(AZStd::forward<Args>(args)...) {}
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /media/slapin/data/o3de-projects/pong/build/linux/o3de/Code/Framework/AzCore/CMakeFiles/AzCore.dir/Unity/unity_15_cxx.cxx:15:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp: In function ‘AZ::Metrics::Script::ReflectRecordEvent(AZ::BehaviorContext&)::<lambda(AZ::Metrics::EventLoggerId, AZ::Metrics::EventPhaseNamespace::EventPhase, AZ::Metrics::Script::ScriptEventArgs, AZ::Metrics::IEventLoggerFactory*)>’:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp:465:66: note: unnamed temporary defined here
  465 |                     asyncArgs.m_id = eventPhaseArgs.m_id.value_or(AZStd::string_view{});
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/string/string.h:430:30: error: dangling pointer to an unnamed temporary may be used [-Werror=dangling-pointer=]
  430 |                 return assign(AZStd::to_address(first), ranges::distance(first, last));
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.cpp: In member function ‘virtual void AzToolsFramework::DocumentPropertyEditor::SetSavedStateKey(AZ::u32, AZStd::string)’:
/media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.cpp:1419:58: note: unnamed temporary defined here
 1419 |         AZStd::string_view keyStr = AZStd::string::format("uuid%s", AZStd::to_string(key).c_str());
      |                                     ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@slapin
Copy link
Author

slapin commented Apr 20, 2024

I see, so gcc-13 I use has false-positives about -Wdangling-pointer so these are better be disabled using pragmas.

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from 9b5e0a8 to a0e0cd7 Compare April 20, 2024 13:16
@slapin slapin requested a review from a team as a code owner April 20, 2024 13:16
@slapin
Copy link
Author

slapin commented Apr 20, 2024

Mitigated -Wdangling-pointer errors using pragmas for easier review.

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from a0e0cd7 to 5e4324d Compare April 20, 2024 14:18
@nick-l-o3de
Copy link
Contributor

nick-l-o3de commented Apr 20, 2024

About dangling pointers -Wdangling-pointer

/media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/variant_impl.h:410:19: error: dangling pointer to an unnamed temporary may be used [-Werror=dangling-pointer=]
  410 |                 : m_value(AZStd::forward<Args>(args)...) {}
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /media/slapin/data/o3de-projects/pong/build/linux/o3de/Code/Framework/AzCore/CMakeFiles/AzCore.dir/Unity/unity_15_cxx.cxx:15:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp: In function ‘AZ::Metrics::Script::ReflectRecordEvent(AZ::BehaviorContext&)::<lambda(AZ::Metrics::EventLoggerId, AZ::Metrics::EventPhaseNamespace::EventPhase, AZ::Metrics::Script::ScriptEventArgs, AZ::Metrics::IEventLoggerFactory*)>’:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp:465:66: note: unnamed temporary defined here
  465 |                     asyncArgs.m_id = eventPhaseArgs.m_id.value_or(AZStd::string_view{});
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/string/string.h:430:30: error: dangling pointer to an unnamed temporary may be used [-Werror=dangling-pointer=]
  430 |                 return assign(AZStd::to_address(first), ranges::distance(first, last));
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.cpp: In member function ‘virtual void AzToolsFramework::DocumentPropertyEditor::SetSavedStateKey(AZ::u32, AZStd::string)’:
/media/slapin/data/o3de/Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.cpp:1419:58: note: unnamed temporary defined here
 1419 |         AZStd::string_view keyStr = AZStd::string::format("uuid%s", AZStd::to_string(key).c_str());
      |                                     ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is a legitimate error that will cause crashes, FWIW. AZStd::string::format returns a temporary object, and string_view does not capture the acutal memory returned.
any use of keyStr after this moment will cause undefined behavior. Change the string_view to a string. It is not a false positive and could be the source of random crashes and failure of the DPE to remember where you had scrolled to.

I searched the code for additional instances of this, and did not find any.

@slapin
Copy link
Author

slapin commented Apr 20, 2024

/media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/variant_impl.h:410:19: error: dangling pointer to an unnamed temporary may be used [-Werror=dangling-pointer=]
  410 |                 : m_value(AZStd::forward<Args>(args)...) {}
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /media/slapin/data/o3de-projects/pong/build/linux/o3de/Code/Framework/AzCore/CMakeFiles/AzCore.dir/Unity/unity_15_cxx.cxx:15:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp: In function ‘AZ::Metrics::Script::ReflectRecordEvent(AZ::BehaviorContext&)::<lambda(AZ::Metrics::EventLoggerId, AZ::Metrics::EventPhaseNamespace::EventPhase, AZ::Metrics::Script::ScriptEventArgs, AZ::Metrics::IEventLoggerFactory*)>’:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp:465:66: note: unnamed temporary defined here
  465 |                     asyncArgs.m_id = eventPhaseArgs.m_id.value_or(AZStd::string{});
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

The similar thing is here. I tried replacing AZStd::string_view with AZStd::string but it did not work. I wonder what produce dangling-pointer here.

@lemonade-dm
Copy link
Contributor

lemonade-dm commented Apr 20, 2024

/media/slapin/data/o3de/Code/Framework/AzCore/./AzCore/std/containers/variant_impl.h:410:19: error: dangling pointer to an unnamed temporary may be used [-Werror=dangling-pointer=]
  410 |                 : m_value(AZStd::forward<Args>(args)...) {}
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /media/slapin/data/o3de-projects/pong/build/linux/o3de/Code/Framework/AzCore/CMakeFiles/AzCore.dir/Unity/unity_15_cxx.cxx:15:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp: In function ‘AZ::Metrics::Script::ReflectRecordEvent(AZ::BehaviorContext&)::<lambda(AZ::Metrics::EventLoggerId, AZ::Metrics::EventPhaseNamespace::EventPhase, AZ::Metrics::Script::ScriptEventArgs, AZ::Metrics::IEventLoggerFactory*)>’:
/media/slapin/data/o3de/Code/Framework/AzCore/AzCore/Metrics/EventLoggerReflectUtils.cpp:465:66: note: unnamed temporary defined here
  465 |                     asyncArgs.m_id = eventPhaseArgs.m_id.value_or(AZStd::string{});
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

The similar thing is here. I tried replacing AZStd::string_view with AZStd::string but it did not work. I wonder what produce dangling-pointer here.

The asyncArgs.m_id variable is of type AZStd::string_view where the eventPhaseArgs.m_id is an AZStd::optional<AZStd::string>.

The dangling pointer is caused by the temporary AZStd::string{} being returned when the optional does not have an "engaged value" assigned to it.

The fix in this case is to only get a reference to the AZStd::string from the optional if it the optional has a value.

i.e

if (eventPhaseArgs.m_id.has_value())
{
    asyncArgs.m_id = eventPhaseArgs.m_id.value();
}

That makes sure the string_view only points to const char* whose lifetime hasn't expired yet.

Comment on lines 465 to 466
auto tmp = eventPhaseArgs.m_id.value_or(AZStd::string_view{});
asyncArgs.m_id = tmp;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be fixed by checking if the optional has a value before assigning it to the AsyncArgs class ID string_view member

Suggested change
auto tmp = eventPhaseArgs.m_id.value_or(AZStd::string_view{});
asyncArgs.m_id = tmp;
if (eventPhaseArgs.m_id.has_value())
{
asyncArgs.m_id = eventPhaseArgs.m_id.value();
}

@@ -594,18 +594,22 @@ namespace Audio
// warn if there is activity on an object being cleared
if (!m_cActiveEvents.empty())
{
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
Copy link
Contributor

Choose a reason for hiding this comment

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

The call to GetEventIDs, should remove the .c_str() call and assign the result to an AZStd::string.

const AZStd::string sEventString = GetEventIDs("; ");

}

if (!m_cTriggers.empty())
{
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
Copy link
Contributor

Choose a reason for hiding this comment

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

The call to GetTriggerNames, should remove the .c_str() call and assign the result to an AZStd::string.

const AZStd::string sTriggerString = GetTriggerNames("; ", pDebugNameStore);

Comment on lines 336 to 337
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
for (auto& it = ++ m_settingsMap.begin(); it != m_settingsMap.end(); ++it)
Copy link
Contributor

Choose a reason for hiding this comment

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

The temporary that is being returned from m_settingsMap.begin() iterator is being assigned to a reference.

This code should just use plain auto without the ampersand.

Suggested change
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
for (auto& it = ++ m_settingsMap.begin(); it != m_settingsMap.end(); ++it)
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
for (auto it = ++ m_settingsMap.begin(); it != m_settingsMap.end(); ++it)

Comment on lines 108 to 110
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
AzFramework::StringFunc::Append(bufferArg, type.data());
AZ_POP_DISABLE_WARNING_GCC;
Copy link
Contributor

Choose a reason for hiding this comment

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

This line doesn't produce a dangling refefence.
It is actually the call to FetchPythonType above.
That function returns an AZStd::string. So the variable it is being assigned to should be an AZStd::string

AZStd::string_view type = FetchPythonType(*behaviorMethod.GetArgument(argIndex))

Comment on lines 140 to 143
AZStd::string_view type = FetchPythonType(*behaviorProperty.m_setter->GetArgument(1));
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
AzFramework::StringFunc::Append(buffer, type.data());
AZ_POP_DISABLE_WARNING_GCC;
Copy link
Contributor

Choose a reason for hiding this comment

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

repeat: The assignment to the AZStd::string_view type variable above should be changed to be of type AZStd::string

Comment on lines 149 to 153
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
AZStd::string_view type = FetchPythonType(*behaviorProperty.m_getter->GetResult());
AzFramework::StringFunc::Append(buffer, "->");
AzFramework::StringFunc::Append(buffer, type.data());
AZ_POP_DISABLE_WARNING_GCC;
Copy link
Contributor

Choose a reason for hiding this comment

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

repeat: The assignment to the AZStd::string_view type variable should be changed to be of type AZStd::string as that is causing the dangling reference.

Comment on lines +2018 to +2020
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
param.m_value = &const_cast<Type&>(result);
AZ_POP_DISABLE_WARNING_GCC;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this dangling pointer can be fixed, first getting the address of the result variable (which in this case is guaranteed to not be a pointer type because this code is in the else block of an if constexpr statement).
Next that address can have it's constness casted of it.

Suggested change
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
param.m_value = &const_cast<Type&>(result);
AZ_POP_DISABLE_WARNING_GCC;
AZ_PUSH_DISABLE_WARNING_GCC("-Wdangling-pointer");
param.m_value = const_cast<Type*>(&result);
AZ_POP_DISABLE_WARNING_GCC;

Copy link
Author

Choose a reason for hiding this comment

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

Well

param.m_value = const_cast<Type*>(&result);

still ends up as address of local variable :/

Copy link
Author

Choose a reason for hiding this comment

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

everything else was was fixed properly, thanks!

@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from 5e4324d to b53af8a Compare April 21, 2024 13:14
@slapin slapin force-pushed the o3de-gcc-changes-2024032701 branch from b53af8a to fff1daf Compare April 21, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/build Categorizes an issue or PR as relevant to SIG Build. sig/graphics-audio Categorizes an issue or PR as relevant to SIG graphics-audio.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants