]> granicus.if.org Git - clang/commitdiff
Fix undefined behavior (and wrong code, as far as I can tell) in NEON builtin
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 14 Aug 2012 01:28:02 +0000 (01:28 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 14 Aug 2012 01:28:02 +0000 (01:28 +0000)
tablegen code, found by -fcatch-undefined-behavior. I would appreciate if
someone more familiar with the NEON code could point me in the direction of how
to write a test for this. We appear to have essentially no test coverage
whatsoever for these builtins.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161827 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
utils/TableGen/NeonEmitter.cpp

index a58e9049e48c9201d1828e7ae251f805a0d71612..2594648b56f83cfb6adcdb49be7758a561d1f097 100644 (file)
@@ -355,7 +355,7 @@ static QualType getNeonEltType(NeonTypeFlags Flags, ASTContext &Context) {
 bool Sema::CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
   llvm::APSInt Result;
 
-  unsigned mask = 0;
+  uint64_t mask = 0;
   unsigned TV = 0;
   int PtrArgNum = -1;
   bool HasConstPtr = false;
@@ -373,7 +373,7 @@ bool Sema::CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
       return true;
     
     TV = Result.getLimitedValue(64);
-    if ((TV > 63) || (mask & (1 << TV)) == 0)
+    if ((TV > 63) || (mask & (1ULL << TV)) == 0)
       return Diag(TheCall->getLocStart(), diag::err_invalid_neon_type_code)
         << TheCall->getArg(ImmArg)->getSourceRange();
   }
index 2e14b80748b2088ca5ac4a10d3d72aca2f19d6c1..73a2d0ef330c5a5823410ce322dcaa37a4a0d099 100644 (file)
@@ -1504,7 +1504,7 @@ void NeonEmitter::runHeader(raw_ostream &OS) {
       throw TGError(R->getLoc(), "Builtin has no class kind");
 
     int si = -1, qi = -1;
-    unsigned mask = 0, qmask = 0;
+    uint64_t mask = 0, qmask = 0;
     for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
       // Generate the switch case(s) for this builtin for the type validation.
       bool quad = false, poly = false, usgn = false;
@@ -1512,10 +1512,10 @@ void NeonEmitter::runHeader(raw_ostream &OS) {
 
       if (quad) {
         qi = ti;
-        qmask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
+        qmask |= 1ULL << GetNeonEnum(Proto, TypeVec[ti]);
       } else {
         si = ti;
-        mask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
+        mask |= 1ULL << GetNeonEnum(Proto, TypeVec[ti]);
       }
     }