summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorScott Linder <scott@scottlinder.com>2018-12-14 15:38:15 +0000
committerScott Linder <scott@scottlinder.com>2018-12-14 15:38:15 +0000
commitde6beb02a530a8da6e0525e99b9c1ab24252064e (patch)
tree23a53e12d9046af6eb2e210c8cf2b20816819193 /llvm/lib/IR/Verifier.cpp
parenteed7b2eeca6ee764ee3560c66f496cead2247b39 (diff)
downloadbcm5719-llvm-de6beb02a530a8da6e0525e99b9c1ab24252064e.tar.gz
bcm5719-llvm-de6beb02a530a8da6e0525e99b9c1ab24252064e.zip
Implement -frecord-command-line (-frecord-gcc-switches)
Implement options in clang to enable recording the driver command-line in an ELF section. Implement a new special named metadata, llvm.commandline, to support frontends embedding their command-line options in IR/ASM/ELF. This differs from the GCC implementation in some key ways: * In GCC there is only one command-line possible per compilation-unit, in LLVM it mirrors llvm.ident and multiple are allowed. * In GCC individual options are separated by NULL bytes, in LLVM entire command-lines are separated by NULL bytes. The advantage of the GCC approach is to clearly delineate options in the face of embedded spaces. The advantage of the LLVM approach is to support merging multiple command-lines unambiguously, while handling embedded spaces with escaping. Differential Revision: https://reviews.llvm.org/D54487 Clang Differential Revision: https://reviews.llvm.org/D54489 llvm-svn: 349155
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r--llvm/lib/IR/Verifier.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index a31f7cddf6e..7fd6df3e6e0 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -386,6 +386,7 @@ public:
visitModuleFlags(M);
visitModuleIdents(M);
+ visitModuleCommandLines(M);
verifyCompileUnits();
@@ -408,6 +409,7 @@ private:
void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F);
void visitComdat(const Comdat &C);
void visitModuleIdents(const Module &M);
+ void visitModuleCommandLines(const Module &M);
void visitModuleFlags(const Module &M);
void visitModuleFlag(const MDNode *Op,
DenseMap<const MDString *, const MDNode *> &SeenIDs,
@@ -1313,6 +1315,24 @@ void Verifier::visitModuleIdents(const Module &M) {
}
}
+void Verifier::visitModuleCommandLines(const Module &M) {
+ const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline");
+ if (!CommandLines)
+ return;
+
+ // llvm.commandline takes a list of metadata entry. Each entry has only one
+ // string. Scan each llvm.commandline entry and make sure that this
+ // requirement is met.
+ for (const MDNode *N : CommandLines->operands()) {
+ Assert(N->getNumOperands() == 1,
+ "incorrect number of operands in llvm.commandline metadata", N);
+ Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),
+ ("invalid value for llvm.commandline metadata entry operand"
+ "(the operand should be a string)"),
+ N->getOperand(0));
+ }
+}
+
void Verifier::visitModuleFlags(const Module &M) {
const NamedMDNode *Flags = M.getModuleFlagsMetadata();
if (!Flags) return;
OpenPOWER on IntegriCloud