- //If getAllModules gives an error then this isn't a proper
- //bytecode archive
- if ( getAllModules( Modules, &ErrorMessage ) ) return false;
-
- //Finally, if we find any bytecode modules then this is a proper
- //bytecode archive
- return Modules.size();
+ // Scan the archive, trying to load a bitcode member. We only load one to
+ // see if this works.
+ for (iterator I = begin(), E = end(); I != E; ++I) {
+ if (!I->isBitcode())
+ continue;
+
+ std::string FullMemberName =
+ archPath.toString() + "(" + I->getPath().toString() + ")";
+
+ MemoryBuffer *Buffer =
+ MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
+ memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
+ Module *M = ParseBitcodeFile(Buffer);
+ delete Buffer;
+ if (!M)
+ return false; // Couldn't parse bitcode, not a bitcode archive.
+ delete M;
+ return true;
+ }
+
+ return false;