[llvm-bugs] [Bug 43900] New: Memory Corruption with clang-cl
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Nov 4 09:59:54 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=43900
Bug ID: 43900
Summary: Memory Corruption with clang-cl
Product: clang
Version: 9.0
Hardware: PC
OS: other
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: bussyantoine at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Created attachment 22766
--> https://bugs.llvm.org/attachment.cgi?id=22766&action=edit
Reproduction of bug
Hi,
I've encountered a weird bug when using args (https://github.com/Taywee/args)
with clang-cl on Windows 10, in release mode only. Using Visual Studio 2019
debugger, I suspect a memory corruption. Here is the code:
#include "args.hpp"
#include <iostream>
inline auto to_argv(std::vector<std::string>& v)
{
auto r = std::vector<char*>{};
for (auto& e : v)
r.emplace_back(e.data());
r.emplace_back(nullptr);
return r;
}
auto other_main(int argc, char* argv[]) -> int
{
std::cerr << argc << std::endl;
for(auto i = 0; i < argc; ++i)
std::cerr << argv[i] << std::endl;
auto parser = args::ArgumentParser{ "Command Line" };
auto const help = args::HelpFlag{ parser, "help", "Display this help
menu", {'h', "help"} };
try
{
parser.ParseCLI(argc, argv);
}
catch (const args::Help&)
{
}
return 0;
}
int main(int argc, char* argv[])
{
auto const commands = std::vector<std::string>
{
"command",
"command_2",
};
for (auto const& command : commands)
{
auto _args = std::vector<std::string>
{
command,
"-h",
};
for (auto const& a : _args)
std::cerr << a << std::endl;
auto args = to_argv(_args);
other_main(static_cast<int>(args.size()) - 1, args.data());
}
}
This should print:
command
-h
2
command
-h
command_2
-h
2
command_2
-h
which it does in debug (or with MSVC or clang on Linux), but it prints:
command
-h
2
command
-h
command_2
2
command_2
-h
In other cases I tested, it prints rubbish, or simply crashes. I attached the
whole self-contained sample, with example cmake commands.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191104/6075daf9/attachment.html>
More information about the llvm-bugs
mailing list