[llvm-commits] [lld] r152389 - in /lld/trunk: CMakeLists.txt include/lld/Core/File.h lib/Core/NativeWriter.cpp lib/Core/YamlReader.cpp lib/Core/YamlWriter.cpp test/multiple-def-error.objtxt
Michael J. Spencer
bigcheesegs at gmail.com
Thu Mar 8 21:27:44 PST 2012
Author: mspencer
Date: Thu Mar 8 23:27:43 2012
New Revision: 152389
URL: http://llvm.org/viewvc/llvm-project?rev=152389&view=rev
Log:
Fix MSVC incompatibilities.
Modified:
lld/trunk/CMakeLists.txt
lld/trunk/include/lld/Core/File.h
lld/trunk/lib/Core/NativeWriter.cpp
lld/trunk/lib/Core/YamlReader.cpp
lld/trunk/lib/Core/YamlWriter.cpp
lld/trunk/test/multiple-def-error.objtxt
Modified: lld/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/CMakeLists.txt?rev=152389&r1=152388&r2=152389&view=diff
==============================================================================
--- lld/trunk/CMakeLists.txt (original)
+++ lld/trunk/CMakeLists.txt Thu Mar 8 23:27:43 2012
@@ -64,13 +64,15 @@
# lld now requires C++11 to build
#
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
-include(CheckCXXCompilerFlag)
-check_cxx_compiler_flag("-std=c++0x" SUPPORTS_CXX11_FLAG)
-if( SUPPORTS_CXX11_FLAG )
- message(STATUS "Building with -std=c++0x")
- set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
-else( SUPPORTS_CXX11_FLAG )
- message(WARNING "-std=c++0x not supported.")
+if (NOT MSVC)
+ include(CheckCXXCompilerFlag)
+ check_cxx_compiler_flag("-std=c++0x" SUPPORTS_CXX11_FLAG)
+ if( SUPPORTS_CXX11_FLAG )
+ message(STATUS "Building with -std=c++0x")
+ set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
+ else( SUPPORTS_CXX11_FLAG )
+ message(WARNING "-std=c++0x not supported.")
+ endif()
endif()
Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=152389&r1=152388&r2=152389&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Thu Mar 8 23:27:43 2012
@@ -188,11 +188,11 @@
class atom_collection_vector : public atom_collection<T> {
public:
virtual atom_iterator<T> begin() const {
- return atom_iterator<T>(*this, reinterpret_cast<const void*>(&_atoms[0]));
+ return atom_iterator<T>(*this, reinterpret_cast<const void*>(_atoms.data()));
}
virtual atom_iterator<T> end() const{
return atom_iterator<T>(*this, reinterpret_cast<const void*>
- (&_atoms[_atoms.size()]));
+ (_atoms.data() + _atoms.size()));
}
virtual const T* deref(const void* it) const {
return *reinterpret_cast<const T* const*>(it);
Modified: lld/trunk/lib/Core/NativeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/NativeWriter.cpp?rev=152389&r1=152388&r2=152389&view=diff
==============================================================================
--- lld/trunk/lib/Core/NativeWriter.cpp (original)
+++ lld/trunk/lib/Core/NativeWriter.cpp Thu Mar 8 23:27:43 2012
@@ -335,8 +335,7 @@
}
// first use of this library name
uint32_t result = this->getNameOffset(name);
- _sharedLibraryNames.push_back(
- std::make_pair<llvm::StringRef, uint32_t>(name, result));
+ _sharedLibraryNames.push_back(std::make_pair(name, result));
return result;
}
@@ -390,8 +389,7 @@
}
// first use of this section name
uint32_t result = this->getNameOffset(name);
- _sectionNames.push_back(
- std::make_pair<llvm::StringRef, uint32_t>(name, result));
+ _sectionNames.push_back(std::make_pair(name, result));
return result;
}
Modified: lld/trunk/lib/Core/YamlReader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/YamlReader.cpp?rev=152389&r1=152388&r2=152389&view=diff
==============================================================================
--- lld/trunk/lib/Core/YamlReader.cpp (original)
+++ lld/trunk/lib/Core/YamlReader.cpp Thu Mar 8 23:27:43 2012
@@ -22,6 +22,7 @@
#include "lld/Platform/Platform.h"
+#include "llvm/ADT/APInt.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/ArrayRef.h"
@@ -934,7 +935,9 @@
haveAtom = true;
}
else if (strcmp(entry->key, KeyValues::valueKeyword) == 0) {
- llvm::StringRef(entry->value).getAsInteger(0, atomState._value);
+ llvm::APInt Val;
+ llvm::StringRef(entry->value).getAsInteger(0, Val);
+ atomState._value = Val.getZExtValue();
haveAtom = true;
}
else {
@@ -953,8 +956,9 @@
haveFixup = true;
}
else if (strcmp(entry->key, KeyValues::fixupsOffsetKeyword) == 0) {
- llvm::StringRef(entry->value).getAsInteger(0,
- atomState._ref._offsetInAtom);
+ llvm::APInt Val;
+ llvm::StringRef(entry->value).getAsInteger(0, Val);
+ atomState._ref._offsetInAtom = Val.getZExtValue();
haveFixup = true;
}
else if (strcmp(entry->key, KeyValues::fixupsTargetKeyword) == 0) {
@@ -962,8 +966,19 @@
haveFixup = true;
}
else if (strcmp(entry->key, KeyValues::fixupsAddendKeyword) == 0) {
- llvm::StringRef(entry->value).getAsInteger(0,
- atomState._ref._addend);
+ llvm::APInt Val;
+ // HACK: getAsInteger for APInt doesn't handle negative values
+ // the same as other getAsInteger functions. And getAsInteger
+ // doesn't work on all platforms for {,u}int64_t. So manually
+ // handle this until getAsInteger is fixed.
+ bool IsNeg = false;
+ llvm::StringRef Addend(entry->value);
+ if (Addend.find('-') == 0) {
+ IsNeg = true;
+ Addend = Addend.substr(1);
+ }
+ Addend.getAsInteger(0, Val);
+ atomState._ref._addend = Val.getSExtValue() * (IsNeg ? -1 : 1);
haveFixup = true;
}
}
Modified: lld/trunk/lib/Core/YamlWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/YamlWriter.cpp?rev=152389&r1=152388&r2=152389&view=diff
==============================================================================
--- lld/trunk/lib/Core/YamlWriter.cpp (original)
+++ lld/trunk/lib/Core/YamlWriter.cpp Thu Mar 8 23:27:43 2012
@@ -19,10 +19,13 @@
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h"
#include <vector>
@@ -62,9 +65,10 @@
const Reference* ref = *rit;
// create refname for any unnamed reference target
if ( ref->target()->name().empty() ) {
- char* buffer;
- asprintf(&buffer, "L%03d", _unnamedCounter++);
- _refNames[ref->target()] = buffer;
+ std::string Storage;
+ llvm::raw_string_ostream Buffer(Storage);
+ Buffer << llvm::format("L%03d", _unnamedCounter++);
+ _refNames[ref->target()] = Buffer.str();
}
}
}
@@ -92,15 +96,16 @@
NameToAtom::iterator pos = _nameMap.find(atom.name());
if ( pos != _nameMap.end() ) {
// Found name collision, give each a unique ref-name.
- char* buffer;
- asprintf(&buffer, "%s.%03d", atom.name().data(), ++_collisionCount);
- _refNames[&atom] = buffer;
+ std::string Storage;
+ llvm::raw_string_ostream Buffer(Storage);
+ Buffer << atom.name() << llvm::format(".%03d", ++_collisionCount);
+ _refNames[&atom] = Buffer.str();
const Atom* prevAtom = pos->second;
AtomToRefName::iterator pos2 = _refNames.find(prevAtom);
if ( pos2 == _refNames.end() ) {
// only create ref-name for previous if none already created
- asprintf(&buffer, "%s.%03d", prevAtom->name().data(), ++_collisionCount);
- _refNames[prevAtom] = buffer;
+ Buffer << prevAtom->name() << llvm::format(".%03d", ++_collisionCount);
+ _refNames[prevAtom] = Buffer.str();
}
}
else {
@@ -113,21 +118,13 @@
return _refNames.count(atom);
}
- const char* refName(const Atom* atom) {
+ llvm::StringRef refName(const Atom* atom) {
return _refNames.find(atom)->second;
}
private:
- struct MyMappingInfo {
- static llvm::StringRef getEmptyKey() { return llvm::StringRef(); }
- static llvm::StringRef getTombstoneKey() { return llvm::StringRef(" ", 0); }
- static unsigned getHashValue(llvm::StringRef const val) {
- return llvm::HashString(val); }
- static bool isEqual(llvm::StringRef const lhs,
- llvm::StringRef const rhs) { return lhs.equals(rhs); }
- };
- typedef llvm::DenseMap<llvm::StringRef, const Atom*, MyMappingInfo> NameToAtom;
- typedef llvm::DenseMap<const Atom*, const char*> AtomToRefName;
+ typedef llvm::StringMap<const Atom*> NameToAtom;
+ typedef llvm::DenseMap<const Atom*, std::string> AtomToRefName;
unsigned int _collisionCount;
unsigned int _unnamedCounter;
Modified: lld/trunk/test/multiple-def-error.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/multiple-def-error.objtxt?rev=152389&r1=152388&r2=152389&view=diff
==============================================================================
--- lld/trunk/test/multiple-def-error.objtxt (original)
+++ lld/trunk/test/multiple-def-error.objtxt Thu Mar 8 23:27:43 2012
@@ -1,9 +1,11 @@
-# RUN: lld-core %s 2>&1 | grep "duplicate symbol"
+# RUN: lld-core %s 2>&1 | FileCheck %s
#
# Test that multiple definitions cause an error
#
+# CHECK: duplicate symbol
+
---
atoms:
- name: _foo
@@ -17,4 +19,3 @@
scope: global
type: data
...
-
More information about the llvm-commits
mailing list