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

[C++20][Modules] error: '_freea' has different definitions in different modules #79386

Closed
Ivan171 opened this issue Jan 24, 2024 · 6 comments
Closed
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@Ivan171
Copy link

Ivan171 commented Jan 24, 2024

Environment

Windows 10
Clang 18.0.0git (https://github.com/llvm/llvm-project f9da4c6)
MSVC 17.8.3

Reproducer

// mod2.cpp

module;

#include <algorithm>

export module mod2;
// mod1.cpp

module;

#include <string_view>

export module mod1;

import mod2;
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod2.cpp --precompile
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod1.cpp -fprebuilt-module-path=.
In module 'mod2' imported from mod1.cpp:7:
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\malloc.h:150:29: error: '_freea' has different definitions in
      different modules; definition in module 'mod2.<global>' first difference is function body
  150 |     __inline void __CRTDECL _freea(_Pre_maybenull_ _Post_invalid_ void* _Memory)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151 |     {
      |     ~
  152 |         unsigned int _Marker;
      |         ~~~~~~~~~~~~~~~~~~~~~
  153 |         if (_Memory)
      |         ~~~~~~~~~~~~
  154 |         {
      |         ~
  155 |             _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156 |             _Marker = *(unsigned int*)_Memory;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157 |             if (_Marker == _ALLOCA_S_HEAP_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158 |             {
      |             ~
  159 |                 free(_Memory);
      |                 ~~~~~~~~~~~~~~
  160 |             }
      |             ~
  161 |             #ifdef _ASSERTE
      |             ~~~~~~~~~~~~~~~
  162 |             else if (_Marker != _ALLOCA_S_STACK_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163 |             {
      |             ~
  164 |                 _ASSERTE(("Corrupted pointer passed to _freea" && 0));
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165 |             }
      |             ~
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\malloc.h:150:29: note: but in '' found a different body
  150 |     __inline void __CRTDECL _freea(_Pre_maybenull_ _Post_invalid_ void* _Memory)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151 |     {
      |     ~
  152 |         unsigned int _Marker;
      |         ~~~~~~~~~~~~~~~~~~~~~
  153 |         if (_Memory)
      |         ~~~~~~~~~~~~
  154 |         {
      |         ~
  155 |             _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156 |             _Marker = *(unsigned int*)_Memory;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157 |             if (_Marker == _ALLOCA_S_HEAP_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158 |             {
      |             ~
  159 |                 free(_Memory);
      |                 ~~~~~~~~~~~~~~
  160 |             }
      |             ~
  161 |             #ifdef _ASSERTE
      |             ~~~~~~~~~~~~~~~
  162 |             else if (_Marker != _ALLOCA_S_STACK_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163 |             {
      |             ~
  164 |                 _ASSERTE(("Corrupted pointer passed to _freea" && 0));
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165 |             }
      |             ~
1 error generated.
@Ivan171
Copy link
Author

Ivan171 commented Jan 24, 2024

Preprocessed files

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 24, 2024

@llvm/issue-subscribers-clang-modules

Author: Ivan171 (Ivan171)

### Environment Windows 10 Clang 18.0.0git (https://github.com/llvm/llvm-project f9da4c6) MSVC 17.8.3

Reproducer

// mod2.cpp

module;

#include &lt;algorithm&gt;

export module mod2;
// mod1.cpp

module;

#include &lt;string_view&gt;

export module mod1;

import mod2;
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod2.cpp --precompile
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod1.cpp -fprebuilt-module-path=.
In module 'mod2' imported from mod1.cpp:7:
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\malloc.h:150:29: error: '_freea' has different definitions in
      different modules; definition in module 'mod2.&lt;global&gt;' first difference is function body
  150 |     __inline void __CRTDECL _freea(_Pre_maybenull_ _Post_invalid_ void* _Memory)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151 |     {
      |     ~
  152 |         unsigned int _Marker;
      |         ~~~~~~~~~~~~~~~~~~~~~
  153 |         if (_Memory)
      |         ~~~~~~~~~~~~
  154 |         {
      |         ~
  155 |             _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156 |             _Marker = *(unsigned int*)_Memory;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157 |             if (_Marker == _ALLOCA_S_HEAP_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158 |             {
      |             ~
  159 |                 free(_Memory);
      |                 ~~~~~~~~~~~~~~
  160 |             }
      |             ~
  161 |             #ifdef _ASSERTE
      |             ~~~~~~~~~~~~~~~
  162 |             else if (_Marker != _ALLOCA_S_STACK_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163 |             {
      |             ~
  164 |                 _ASSERTE(("Corrupted pointer passed to _freea" &amp;&amp; 0));
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165 |             }
      |             ~
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\malloc.h:150:29: note: but in '' found a different body
  150 |     __inline void __CRTDECL _freea(_Pre_maybenull_ _Post_invalid_ void* _Memory)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151 |     {
      |     ~
  152 |         unsigned int _Marker;
      |         ~~~~~~~~~~~~~~~~~~~~~
  153 |         if (_Memory)
      |         ~~~~~~~~~~~~
  154 |         {
      |         ~
  155 |             _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156 |             _Marker = *(unsigned int*)_Memory;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157 |             if (_Marker == _ALLOCA_S_HEAP_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158 |             {
      |             ~
  159 |                 free(_Memory);
      |                 ~~~~~~~~~~~~~~
  160 |             }
      |             ~
  161 |             #ifdef _ASSERTE
      |             ~~~~~~~~~~~~~~~
  162 |             else if (_Marker != _ALLOCA_S_STACK_MARKER)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163 |             {
      |             ~
  164 |                 _ASSERTE(("Corrupted pointer passed to _freea" &amp;&amp; 0));
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165 |             }
      |             ~
1 error generated.

@ChuanqiXu9
Copy link
Member

Maybe the reproducer can be fixed if we make #79240

@ChuanqiXu9
Copy link
Member

@Ivan171 I've landed #79240. Could you try to test again and your original workload?

@Ivan171
Copy link
Author

Ivan171 commented Jan 30, 2024

@Ivan171 I've landed #79240. Could you try to test again and your original workload?

That fixed it.

I'm converting my project to modules, one file at time. I have maybe 10% or 15% converted, and today was the first time I got it to build without any errors. I'll keep converting it and if any error shows up, I'll try to reduce it and report it.

Thanks!

@Ivan171 Ivan171 closed this as completed Jan 30, 2024
@ChuanqiXu9
Copy link
Member

@Ivan171 I've landed #79240. Could you try to test again and your original workload?

That fixed it.

I'm converting my project to modules, one file at time. I have maybe 10% or 15% converted, and today was the first time I got it to build without any errors. I'll keep converting it and if any error shows up, I'll try to reduce it and report it.

Thanks!

Thanks for reporting it too.

BTW, if you're making a toy and want to get a feeling about modules, it is suggested to use std modules from https://libcxx.llvm.org/Modules.html. Or if you still want to use libstdc++, it is suggested to mock a std module for that by yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules
Projects
None yet
Development

No branches or pull requests

4 participants