[llvm-commits] [llvm] r158457 - /llvm/trunk/include/llvm/ADT/FlatArrayMap.h

Benjamin Kramer benny.kra at googlemail.com
Thu Jun 14 10:13:13 PDT 2012


On 14.06.2012, at 18:59, Stepan Dyatkovskiy wrote:

> Author: dyatkovskiy
> Date: Thu Jun 14 11:59:43 2012
> New Revision: 158457
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=158457&view=rev
> Log:
> SmallMap, FlatArrayMap::copyFrom
> Replaced memcpy with std::copy, since the first one may work improperly with non POD data.

A unit test would be nice. You can count ctor + dtor calls with a global variable and a simple class, then do some operations on the map and assert that the counters match.

- Ben
> 
> Modified:
>    llvm/trunk/include/llvm/ADT/FlatArrayMap.h
> 
> Modified: llvm/trunk/include/llvm/ADT/FlatArrayMap.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/FlatArrayMap.h?rev=158457&r1=158456&r2=158457&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/FlatArrayMap.h (original)
> +++ llvm/trunk/include/llvm/ADT/FlatArrayMap.h Thu Jun 14 11:59:43 2012
> @@ -96,11 +96,13 @@
> 
> 
>   void copyFrom(const self &RHS) {
> -    memcpy(Array, RHS.Array, sizeof(value_type) * (MaxArraySize + 1));
> +    std::copy(RHS.Array, RHS.Array + MaxArraySize + 1, Array);
>     NumElements = RHS.NumElements;
>   }
> 
>   void init () {
> +    // Even if Array contains non POD, use memset for last element,
> +    // since it is used as end() iterator only.
>     memset(Array + MaxArraySize, 0, sizeof(value_type));
>     NumElements = 0;
>   }
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list