<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Memory Corruption with clang-cl"
href="https://bugs.llvm.org/show_bug.cgi?id=43900">43900</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Memory Corruption with clang-cl
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>other
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bussyantoine@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=22766" name="attach_22766" title="Reproduction of bug">attachment 22766</a> <a href="attachment.cgi?id=22766&action=edit" title="Reproduction of bug">[details]</a></span>
Reproduction of bug
Hi,
I've encountered a weird bug when using args (<a href="https://github.com/Taywee/args">https://github.com/Taywee/args</a>)
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>