[clang][cli] Ensure plugin args are generated in deterministic order

The '-plugin-arg' command-line arguments are not being generated in deterministic order.

This patch changes the storage from `std::unordered_map` to `std::map` to enforce ordering.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D99879
This commit is contained in:
Jan Svoboda 2021-04-05 12:15:50 +02:00
parent 98742e42fc
commit cc26943313
2 changed files with 13 additions and 2 deletions

View File

@ -16,9 +16,9 @@
#include "clang/Serialization/ModuleFileExtension.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
namespace llvm {
@ -404,7 +404,7 @@ public:
std::string ActionName;
/// Args to pass to the plugins
std::unordered_map<std::string,std::vector<std::string>> PluginArgs;
std::map<std::string, std::vector<std::string>> PluginArgs;
/// The list of plugin actions to run in addition to the normal action.
std::vector<std::string> AddPluginActions;

View File

@ -877,4 +877,15 @@ TEST_F(CommandLineTest, RoundTrip) {
ShowIncludesDestination::Stdout);
ASSERT_TRUE(Invocation.getDependencyOutputOpts().ShowHeaderIncludes);
}
TEST_F(CommandLineTest, PluginArgsRoundTripDeterminism) {
const char *Args[] = {
"-plugin-arg-blink-gc-plugin", "no-members-in-stack-allocated",
"-plugin-arg-find-bad-constructs", "checked-ptr-as-trivial-member",
"-plugin-arg-find-bad-constructs", "check-ipc",
// Enable round-trip to ensure '-plugin-arg' generation is deterministic.
"-round-trip-args"};
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
}
} // anonymous namespace