[llvm-commits] CVS: llvm/lib/Support/CommandLine.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue May 10 16:20:35 PDT 2005
Changes in directory llvm/lib/Support:
CommandLine.cpp updated: 1.59 -> 1.60
---
Log message:
Do not use "" as a sentinal for a missing argument! This fixes PR560: http://llvm.cs.uiuc.edu/PR560 .
---
Diffs of the changes: (+12 -11)
CommandLine.cpp | 23 ++++++++++++-----------
1 files changed, 12 insertions(+), 11 deletions(-)
Index: llvm/lib/Support/CommandLine.cpp
diff -u llvm/lib/Support/CommandLine.cpp:1.59 llvm/lib/Support/CommandLine.cpp:1.60
--- llvm/lib/Support/CommandLine.cpp:1.59 Thu Apr 21 17:52:05 2005
+++ llvm/lib/Support/CommandLine.cpp Tue May 10 18:20:17 2005
@@ -97,7 +97,7 @@
// Enforce value requirements
switch (Handler->getValueExpectedFlag()) {
case ValueRequired:
- if (Value == 0 || *Value == 0) { // No value specified?
+ if (Value == 0) { // No value specified?
if (i+1 < argc) { // Steal the next argument, like for '-o filename'
Value = argv[++i];
} else {
@@ -106,7 +106,7 @@
}
break;
case ValueDisallowed:
- if (*Value != 0)
+ if (Value)
return Handler->error(" does not allow a value! '" +
std::string(Value) + "' specified.");
break;
@@ -121,7 +121,7 @@
}
// Run the handler now!
- return Handler->addOccurrence(i, ArgName, Value);
+ return Handler->addOccurrence(i, ArgName, Value ? Value : "");
}
static bool ProvidePositionalOption(Option *Handler, const std::string &Arg,
@@ -268,11 +268,11 @@
const char *ArgEnd = Arg;
while (*ArgEnd && *ArgEnd != '=')
- ++ArgEnd; // Scan till end of argument name...
+ ++ArgEnd; // Scan till end of argument name.
+
+ if (*ArgEnd == '=') // If we have an equals sign...
+ Value = ArgEnd+1; // Get the value, not the equals
- Value = ArgEnd;
- if (*Value) // If we have an equals sign...
- ++Value; // Advance to value...
if (*Arg == 0) return 0;
@@ -348,7 +348,7 @@
bool DashDashFound = false; // Have we read '--'?
for (int i = 1; i < argc; ++i) {
Option *Handler = 0;
- const char *Value = "";
+ const char *Value = 0;
const char *ArgName = "";
// Check to see if this is a positional argument. This argument is
@@ -429,7 +429,7 @@
"Option can not be cl::Grouping AND cl::ValueRequired!");
int Dummy;
ErrorParsing |= ProvideOption(PGOpt, RealArgName.c_str(),
- "", 0, 0, Dummy);
+ 0, 0, 0, Dummy);
// Get the next grouping option...
PGOpt = getOptionPred(RealName, Length, isGrouping);
@@ -450,7 +450,7 @@
// Check to see if this option accepts a comma separated list of values. If
// it does, we have to split up the value into multiple values...
- if (Handler->getMiscFlags() & CommaSeparated) {
+ if (Value && Handler->getMiscFlags() & CommaSeparated) {
std::string Val(Value);
std::string::size_type Pos = Val.find(',');
@@ -591,7 +591,8 @@
return true;
}
-bool Option::addOccurrence(unsigned pos, const char *ArgName, const std::string &Value) {
+bool Option::addOccurrence(unsigned pos, const char *ArgName,
+ const std::string &Value) {
NumOccurrences++; // Increment the number of times we have been seen
switch (getNumOccurrencesFlag()) {
More information about the llvm-commits
mailing list